<?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.33, 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.2.0 - 7.2.34
- 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 (
),
),
)
---
preferences:
96.47 ms | 421 KiB | 5 Q