I'm editing someone else's code here:
foreach($list as $items) {
// displays items names and images etc
}
and within the foreach() loop I can see the name using:
echo $items[0]->name
and looking at the contents of $items it looks like this:
Array ( [0] => stdClass Object ( [id] => 7 [name] => Bench Scales // ..etc..
But I can't seem to reference name outside the loop
$list[0]->name // doesn't work
So I'm kinda stuck at this point when trying to sort by name, Yep I've looked up usort() and am happy with the concept of sorting by name, but am unable to sort this array of objects? by name. Any help most welcome
Above the foreach() loop I tried something like this, but no luck:
function cmp($a,$b) { return strcmp($a->name, $b->name); }
usort($list,"cmp");
$list[0]->name
is not the same as$items[0]->name
. Why do you think they are interchangeable? – zerkms Dec 9 '13 at 2:47$items[0]->name
and in comparison function -$a->name
. What makes you thinking that[0]
is an optional element? – zerkms Dec 9 '13 at 2:54