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.
1) Ordering of a multidimensional array ($array) by value of key "position":
// ARRAY BEFORE
Array
(
[0] => Array
(
[ftid] => 3339685
[position] => 2
[auswahl] => 7179726
[keine_antwort] =>
)
[1] => Array
(
[ftid] => 3339686
[position] => 1
[auswahl] => 7179727
[keine_antwort] =>
)
)
// FUNCTION THAT NEEDS TO BE REWRITTEN
usort($array, function($a, $b) {
return $a['position'] - $b['position'];
});
// ARRAY AFTER
Array
(
[0] => Array
(
[ftid] => 3339686
[position] => 1
[auswahl] => 7179727
[keine_antwort] =>
)
[1] => Array
(
[ftid] => 3339685
[position] => 2
[auswahl] => 7179726
[keine_antwort] =>
)
)
2) Ordering of a multidimensional array ($array) according to the order of a second array ($position_order):
// $array before
Array
(
[0] => Array
(
[ftid] => 3339685
[position] => 1
[auswahl] => 7179726
[keine_antwort] =>
)
[1] => Array
(
[ftid] => 3339686
[position] => 2
[auswahl] => 7179727
[keine_antwort] =>
)
)
// $position_order (key value corresponds to key 'ftid' in $array
Array
(
[3339686] => 1
[3339685] => 2
)
// FUNCTION THAT NEEDS TO BE REWRITTEN
usort($array, function($a, $b) use($position_order) {
return (isset($position_order[$a['ftid']]) ? ($position_order[$a['ftid']] - $position_order[$b['ftid']]) : 1);
});
// $array
Array
(
[0] => Array
(
[ftid] => 3339686
[position] => 2
[auswahl] => 7179727
[keine_antwort] =>
)
[1] => Array
(
[ftid] => 3339685
[position] => 1
[auswahl] => 7179726
[keine_antwort] =>
)
)
Especially the latter causes some headache, as we don't know how to pass the "outside" array $position_order.