search

Home  >  Q&A  >  body text

Questions about array_multisort($name,SORT_ASC,$age,SORT_DESC,$arr);;

This function should be

array_multisort(array1,sorting order,sorting type,array2,array3...)

So sort $name first, and then $age Sort, then sort $arr.

The final returned result is represented by print_r($arr), that is, only $arr is sorted.

It is not returned to $arr as the teacher said.

array_multisort($name,SORT_ASC,$age,SORT_DESC);

The result of sorting in this way is a sort that does not retain the corresponding relationship between the original key values,

print_r( $arr) in this case the output is a two-dimensional array sorted forward by name and reversely sorted by age.

太山遍雨河润千里太山遍雨河润千里2511 days ago1562

reply all(1)I'll reply

  • Rain

    Rain2018-07-18 13:12:31

    After repeated debugging, it was found that the $arr parameter of the array_multisort function is equivalent to appending the sorting changes made by the previous parameters to the
    $arr ​​ontology array, because the array_multisort function is passed by value. When calling, the previous sorting operation is an operation on the copy. The $arr parameter is equivalent to a
    reassignment, ensuring the change of the ontology. But it cannot be completely regarded as a reassignment operation, because when the $arr parameter is changed to a new array $newArr parameter, the system will report an error. It can be seen that the role of the $arr parameter is similar to that of reassignment. Assignment operation but not.

    reply
    0
  • Cancelreply