I need to use create_functionit because the server the application is running on has an outdated version of PHP.
The problem is that the elements that I pass in usortare arrays, and I need to sort by value inside the array:
$sort_dist = create_function( '$a, $b', "
if( $a['order-dir'] == 'asc' ) {
return $a['distance'] > $b['distance'];
}
else {
return $a['distance'] < $b['distance'];
}"
);
usort( $items, $sort_dist );
Gives an error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING
Removing links to ['distance']and ['order-dir']resolves this error.
Does anyone know how to use create_functionwith nested arrays?
Matt source
share