CodeIgniter Forums
Help with Looping through an object - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Help with Looping through an object (/showthread.php?tid=72137)

Pages: 1 2


RE: Help with Looping through an object - enelson - 11-13-2018

(11-12-2018, 01:06 AM)paulkd Wrote: Hi,

I got this answer from https://stackoverflow.com/questions/4282413/sort-array-of-objects-by-object-fields

Code:
$list = json_decode($json);

function cmp($a, $b) {
   return strcmp($a->data_amount, $b->data_amount);
}

usort($list->products, "cmp");

Unfortunately, this returns bool(true) instead of the original objects


RE: Help with Looping through an object - paulkd - 11-13-2018

Hi enelson,

Can you show me your code?