I did some tasks using the array_multisort function. During the writing of the script I did a var_dump, and got different results of $mainArray depending on the PHP version. Here is the code:
$mainArray = array(
0 =>array(
"key1" => array(7,4,5),
'key2' => array('cc','aa')
)
);
foreach($mainArray as $secondArray){
foreach($secondArray as $array){
array_multisort($array);
}
}
var_dump($mainArray);
Output for 4.3.10 - 4.4.9, 5.1.1 - 5.5.7:
array(1) {
[0]=> array(2) {
["key1"]=> array(3) {
[0]=> int(7)
[1]=> int(4)
[2]=> int(5) }
["key2"]=> array(2) {
[0]=> string(2) "cc"
[1]=> string(2) "aa" }
}
}
But Output for 4.3.0 - 4.3.9, 5.0.0 - 5.0.5 I get sorted array:
array(1) {
[0]=> array(2) {
["key1"]=> array(3) {
[0]=> int(4)
[1]=> int(5)
[2]=> int(7) }
["key2"]=> array(2) {
[0]=> string(2) "aa"
[1]=> string(2) "cc" }
}
}
I knew that array_multisort($array) would not have influence on $mainArray but:
I really do not understand why in the second variant it was sorted, and in the first one is not. And, should I always check the script in different php versions?
Here you can check the script
array_multisortwith a single array?