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, function($a, $b) { return [$b['boolean'], $a['float']] <=> [$a['boolean'], $b['float']]; }); var_export($multidimArray); echo "\n---\n"; //Sorting logic: mixed ASC, object ASC, boolean ASC uasort($multidimArray, function($a, $b) { return [$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, function($a, $b) { return [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); echo "\n---\n";
Output for 7.3.0 - 7.3.28, 7.4.0 - 7.4.13, 8.0.0 - 8.0.3
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.1.26 - 7.1.33, 7.2.17 - 7.2.33
array ( 'd' => array ( 'boolean' => true, 'natString' => 'text1', 'object' => stdClass::__set_state(array( 'prop' => 9, )), 'float' => -5, 'mixed' => '' . "\0" . '', ), 'a' => array ( 'boolean' => true, 'natString' => 'text10', 'object' => stdClass::__set_state(array( 'prop' => 2, )), 'float' => -0.5, 'mixed' => array ( ), ), 'b' => array ( 'boolean' => true, 'natString' => 'text12', 'object' => stdClass::__set_state(array( 'prop' => 4, )), 'float' => 0, 'mixed' => NULL, ), 'c' => array ( 'boolean' => false, 'natString' => 'text100', 'object' => stdClass::__set_state(array( 'prop' => 9, )), 'float' => -0.5, 'mixed' => false, ), 'e' => array ( 'boolean' => false, 'natString' => 'text2', 'object' => stdClass::__set_state(array( 'prop' => 2, )), 'float' => 0.5, 'mixed' => '', ), ) --- array ( 'e' => array ( 'boolean' => false, 'natString' => 'text2', 'object' => stdClass::__set_state(array( 'prop' => 2, )), 'float' => 0.5, 'mixed' => '', ), 'd' => array ( 'boolean' => true, 'natString' => 'text1', 'object' => stdClass::__set_state(array( 'prop' => 9, )), 'float' => -5, 'mixed' => '' . "\0" . '', ), 'a' => array ( 'boolean' => true, 'natString' => 'text10', 'object' => stdClass::__set_state(array( 'prop' => 2, )), 'float' => -0.5, 'mixed' => array ( ), ), 'b' => array ( 'boolean' => true, 'natString' => 'text12', 'object' => stdClass::__set_state(array( 'prop' => 4, )), 'float' => 0, 'mixed' => NULL, ), 'c' => array ( 'boolean' => false, 'natString' => 'text100', 'object' => stdClass::__set_state(array( 'prop' => 9, )), 'float' => -0.5, 'mixed' => false, ), ) --- array ( 'd' => array ( 'boolean' => true, 'natString' => 'text1', 'object' => stdClass::__set_state(array( 'prop' => 9, )), 'float' => -5, 'mixed' => '' . "\0" . '', ), 'e' => array ( 'boolean' => false, 'natString' => 'text2', 'object' => stdClass::__set_state(array( 'prop' => 2, )), 'float' => 0.5, 'mixed' => '', ), 'b' => array ( 'boolean' => true, 'natString' => 'text12', 'object' => stdClass::__set_state(array( 'prop' => 4, )), 'float' => 0, 'mixed' => NULL, ), 'c' => array ( 'boolean' => false, 'natString' => 'text100', 'object' => stdClass::__set_state(array( 'prop' => 9, )), 'float' => -0.5, 'mixed' => false, ), 'a' => array ( 'boolean' => true, 'natString' => 'text10', 'object' => stdClass::__set_state(array( 'prop' => 2, )), 'float' => -0.5, 'mixed' => array ( ), ), ) ---