How to use array multisort in PHP

In this article, I will explain how the array_multisort() function can be used in PHP.
  • 2265

array_multisort() function in PHP

  • The array_multisort() function returns a sorted array.

  • In array_multisort() function, you can assign one or more arrays.

  • array_multisort() functionit sorts the next array, if two or more values are the same.

Syntax

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

Parameter

  • array1 array1 is required parameter. determine the array name.

  • sorting order sorting order is Optional parameter. Possible values:

    • SORT_ASC It's a default case. Sort in ascending order (A-Z)
    • SORT_DESC sort in descending order (Z-A)
  • sorting type sorting type is Optional parameter. Possible values:

    • SORT_REGULAR  It's a default case. elements Compare normally
    • SORT_NUMERIC elements Compare as numeric values
    • SORT_STRING elements Compare as string values
  • array2 array2 is optional parameter. determine the array name.

  • array3 array3 is optional parameter. specifies an array name.

Example

The following example show to how the array_multisort() function can be used in PHP.

<html>

<body>

<h3 style="color: darkgrey;">array_multisort() function example in PHP</h3>

    <?php

    $s1=array("Nitin","Manish","Priyanka");

    $s2=array("Arvind","Aman","Sachin");

    array_multisort($s1,SORT_ASC,$s2,SORT_DESC);

    print_r($s1);

    print("<br/>");

    print_r($s2);

    ?>

</body>

</html>

 

Output

multisoft.jpg

You may also want to read these related articles here
 
Ask Your Question 
 
Got a programming related question? You may want to post your question here
 

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.