I have a two-dimensional array and want to sort it by name. I would like to use usort() with anonymous functions. How should my comparator function look like when I want to sort something alphabetically?
[names] => Array
(
[0] => Array
(
[name] => Baba
[prename] => Ali
)
[1] => Array
(
[name] => Pan
[prename] => Peter
)
)
To sort, I tried this:
usort($names, function cmp($a, $b) {
return strcmp($a['name'], $b['name']);
});
which gives me unexpected T_STRING, expecting '('
on the first line.