I have this array :
Array
(
[0] => Array
(
[id] => 83
[value] => Figures
)
[1] => Array
(
[id] => 85
[value] => Toys
)
[2] => Array
(
[id] => 36
[value] => Nintendo Switch
)
)
and I have this code to sort that array based on id :
function cmp($a, $b) {
return strcmp($a->id, $b->id);
}
while ($row = $result->fetch_assoc()) {
$category = json_decode($row['product_cat'], true);
usort($category, "cmp");
echo '<pre>';
print_r($category);
echo '</pre>';
}
the result is not working as I expected, because id=85 placed before id=83 :
Array
(
[0] => Array
(
[id] => 36
[value] => Nintendo Switch
)
[1] => Array
(
[id] => 85
[value] => Toys
)
[2] => Array
(
[id] => 83
[value] => Figures
)
)
why PHP successfully placed the id=36 as first value of array, but failed to sort id=85 and id=83
thank you.