Rewriting usort function because of fatal error (PHP bug)
- by Lionel
The two following usort functions throw fatal error Base lambda function for closure not found in our productive environment (PHP 5.4). This seems to be a known PHP bug that should be fixed by now (https://bugs.php.net/bug.php?id=52144), but it still occurs for us.
Anyway, we unfortunately don't have time to figure out what's wrong with our PHP configurations etc. We would like to rewrite these two functions without the use of anonymous functions, so that the error doesn't occur anymore.
Ordering of a multidimensional array ($array) by value of key "position":
usort($array, function($a, $b) {
return $a['position'] - $b['position'];
});
Ordering of a multidimensional array ($array) according to the order of a second array ($position_order):
usort($array, function($a, $b) use($position_order) {
return (isset($position_order[$a['ftid']]) ? ($position_order[$a['ftid']] - $position_order[$b['ftid']]) : 1);
});
Especially the latter causes some headache, as we don't know how to pass the "outside" array $position_order.