I'm trying to sort a multi-dimensional array by one of the values (title) in alphabetical order A-Z, but get an error: Cannot use object of type stdClass as array
I'm using php 7.1
My array is $data and looks like this:
[0] => stdClass Object
(
[id] => 1
[title] => Manager - Chicago Branch
)
[1] => stdClass Object
(
[id] => 2
[title] => Manager - New York Branch
)
[2] => stdClass Object
(
[id] => 3
[title] => Manager - Detroit Branch
)
I've tried the follow, with $jobs being the array and "title" being the field I'm trying to sort by:
function cmp($a, $b) {
return $a["title"] - $b["title"];
}
usort($jobs, "cmp");
I expected the array to sort (without any data being lost) alphabetically sorted by the "title" value, but instead I get the error: "Cannot use object of type stdClass as array"