Thursday 5 June 2014

Array_multisort function in php.

Definition of "PHP array_multisort() Function"-

The array_multisort() function returns a sorted array. You can assign one or more arrays. The function sorts the first array, and the other arrays follow, then, if two or more values are the same, it sorts the next array, and so on.
String keys will be maintained, but numeric keys will be re-indexed, starting at 0 and increase by 1.

You can assign the sorting order and the sorting type parameters after each array. If not specified, each array parameter uses the default values.

Syntax of array_multisort-

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

First Example -

<html>
<body>

<?php
                  $a=array("Dog","Cat","Horse","Bear","Zebra");
                 array_multisort($a);
                 print_r($a);
?>

</body>
</html>

Output-

Array ( [0] => Bear [1] => Cat [2] => Dog [3] => Horse [4] => Zebra )


 Second Example-


array_multisort

















Output-











Posted by Amit Tiwari (Facebook)



No comments:

Post a Comment