3v4l.org

run code in 300+ PHP versions simultaneously
<?php $multidimArray = [ 'a' => [ 'boolean' => true, 'natString' => 'text10', 'object' => (object)['prop' => 2], 'float' => -.5, 'mixed' => [] ], 'b' => [ 'boolean' => true, 'natString' => 'text12', 'object' => (object)['prop' => 4], 'float' => 0, 'mixed' => null ], 'c' => [ 'boolean' => false, 'natString' => 'text100', 'object' => (object)['prop' => 9], 'float' => -.5, 'mixed' => false ], 'd' => [ 'boolean' => true, 'natString' => 'text1', 'object' => (object)['prop' => 9], 'float' => -5, 'mixed' => "\0" ], 'e' => [ 'boolean' => false, 'natString' => 'text2', 'object' => (object)['prop' => 2], 'float' => .5, 'mixed' => '' ] ]; //Sorting logic: boolean DESC (false = 0, true = 1, so trues before falses), float ASC uasort($multidimArray, fn($a, $b) => [$b['boolean'], $a['float']] <=> [$a['boolean'], $b['float']]); var_export($multidimArray); echo "\n---\n"; //Sorting logic: mixed ASC, object ASC, boolean ASC uasort($multidimArray, fn($a, $b) => [$a['mixed'], $a['object']->prop, $a['boolean']] <=> [$b['mixed'], $b['object']->prop, $b['boolean']]); var_export($multidimArray); echo "\n---\n"; //Sorting logic: property count of object ASC, iterability of mixed DESC, natString length ASC, natString ASC uasort($multidimArray, fn($a, $b) => [count(get_object_vars($a['object'])), is_iterable($a['mixed']), strlen($a['natString']), $a['natString']] <=> [count(get_object_vars($b['object'])), is_iterable($b['mixed']), strlen($b['natString']), $b['natString']] ); var_export($multidimArray);
Output for 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.31, 8.2.0 - 8.2.26, 8.3.0 - 8.3.15, 8.4.1 - 8.4.2
array ( 'd' => array ( 'boolean' => true, 'natString' => 'text1', 'object' => (object) array( 'prop' => 9, ), 'float' => -5, 'mixed' => '' . "\0" . '', ), 'a' => array ( 'boolean' => true, 'natString' => 'text10', 'object' => (object) array( 'prop' => 2, ), 'float' => -0.5, 'mixed' => array ( ), ), 'b' => array ( 'boolean' => true, 'natString' => 'text12', 'object' => (object) array( 'prop' => 4, ), 'float' => 0, 'mixed' => NULL, ), 'c' => array ( 'boolean' => false, 'natString' => 'text100', 'object' => (object) array( 'prop' => 9, ), 'float' => -0.5, 'mixed' => false, ), 'e' => array ( 'boolean' => false, 'natString' => 'text2', 'object' => (object) array( 'prop' => 2, ), 'float' => 0.5, 'mixed' => '', ), ) --- array ( 'e' => array ( 'boolean' => false, 'natString' => 'text2', 'object' => (object) array( 'prop' => 2, ), 'float' => 0.5, 'mixed' => '', ), 'd' => array ( 'boolean' => true, 'natString' => 'text1', 'object' => (object) array( 'prop' => 9, ), 'float' => -5, 'mixed' => '' . "\0" . '', ), 'a' => array ( 'boolean' => true, 'natString' => 'text10', 'object' => (object) array( 'prop' => 2, ), 'float' => -0.5, 'mixed' => array ( ), ), 'b' => array ( 'boolean' => true, 'natString' => 'text12', 'object' => (object) array( 'prop' => 4, ), 'float' => 0, 'mixed' => NULL, ), 'c' => array ( 'boolean' => false, 'natString' => 'text100', 'object' => (object) array( 'prop' => 9, ), 'float' => -0.5, 'mixed' => false, ), ) --- array ( 'd' => array ( 'boolean' => true, 'natString' => 'text1', 'object' => (object) array( 'prop' => 9, ), 'float' => -5, 'mixed' => '' . "\0" . '', ), 'e' => array ( 'boolean' => false, 'natString' => 'text2', 'object' => (object) array( 'prop' => 2, ), 'float' => 0.5, 'mixed' => '', ), 'b' => array ( 'boolean' => true, 'natString' => 'text12', 'object' => (object) array( 'prop' => 4, ), 'float' => 0, 'mixed' => NULL, ), 'c' => array ( 'boolean' => false, 'natString' => 'text100', 'object' => (object) array( 'prop' => 9, ), 'float' => -0.5, 'mixed' => false, ), 'a' => array ( 'boolean' => true, 'natString' => 'text10', 'object' => (object) array( 'prop' => 2, ), 'float' => -0.5, 'mixed' => array ( ), ), )
Output for 7.3.0 - 7.3.33
Parse error: syntax error, unexpected '=>' (T_DOUBLE_ARROW), expecting ')' in /in/N5hs1 on line 41
Process exited with code 255.
Output for 7.1.26 - 7.1.33, 7.2.17 - 7.2.33
Parse error: syntax error, unexpected '=>' (T_DOUBLE_ARROW), expecting ',' or ')' in /in/N5hs1 on line 41
Process exited with code 255.

preferences:
86.95 ms | 411 KiB | 5 Q