PHP array_multisort() Function

PHP array_multisort () Function

The array_multisort() function in PHP sorts multiple or multi-dimensional arrays at once.

Syntax

array_multisort ( array &$array1 [, mixed $array1_sort_order [, mixed $array1_sort_flags [, mixed $... ]]] )

Parameter

array1(required)- This parameter specified the input array to sort.

array1_sort_order(optional)- This parameter specifies the order (ascending or descending) to use where SORT_ASC(the default value) is used to sort ascendingly and SORT_DESC is used to sort descendingly.

array1_sort_flags(optional)- This parameter represents the various sort options for the arrays. The sorting flags are as follows:

  • SORT_REGULAR(default value)- It is used to compare items normally without changing the type.
  • SORT_NUMERIC- It is used to compare items numerically
  • SORT_STRING- It compares the items as strings
  • SORT_LOCALE_STRING- It compares items as strings, based on the current locale.
  • SORT_NATURAL- It is used to compare items as strings using "natural ordering" 
  • SORT_FLAG_CASE- It can be combined (bitwise OR) with SORT_STRING or SORT_NATURAL to sort strings case-insensitively

Return

This function returns a Boolean value TRUE on success or FALSE on failure.

Example 1

 

Output

Array before sorting...
 array (
   0 => 10,
   1 => 100,
   2 => 100,
   3 => 0,
 ) 
 Array after sorting...
 array (
   0 => 0,
   1 => 10,
   2 => 100,
   3 => 100,
 ) 

Example 2

 

Output

array (
   0 => 
   array (
     0 => 100,
     1 => 100,
     2 => 101,
     3 => '20', 
     4 => 'value',
   ),
   1 => 
   array (
     0 => '20',
     1 => 13,
     2 => 12, 
     3 => 11,
     4 => 11,
   ),
 ) 

Example 3

   

Output

array (
   0 => 
   array (
     0 => 100,
     1 => 100,
     2 => 101,
     3 => '20',
     4 => 'value',
   ),
   1 =>  
   array (
     0 => '20',
     1 => 13,
     2 => 12,
     3 => 11,
     4 => 11, 
   ),
 ) 

Related Topics

PHP lcfirst() Function

PHP lcfirst() Function The lcfirst() function in PHP converts the first character of a string to lowercase if that character is alphabetic. Syntax lcfirst ( string $str ) Parameter str(required)- This parameter signifies the input string. Return This function returns a string with the...

1 minute read.

PHP Comment

PHP commentis a line of code that is not executed. It is often used by developer to understand the code. PHP support single and multiple comments. In other language like C,...

1 minute read.

PHP htmlentities() Function

PHP htmlentities() Function The htmlentities() function in PHP converts all characters to HTML entities. Syntax htmlentities(string,flags,character-set,double_encode);   Parameter string(required)- This parameter specifies the string to convert. flags(optional)- This parameter specifies how to handle quotes, invalid encoding and the used document type. The...

1 minute read.

How to use Date and Time in PHP

HOW TO USE DATE AND TIME IN PHP: PHP time and date function  informs us about current date and time. it can be manipulated also. How time() function works: The time() function...

2 minutes read.

PHP isset() function

PHP isset is used to check whether the variable is set or not.The PHP isset() function returns false if variable contains a NULL value. Syntax: isset(variable1, variable2….) Presentation of PHP isset: In...

2 minutes read.

PHP array_unshift() Function

PHP array_unshift() Function The array_unshift () function in PHP prepends one or more elements to the beginning or front of an array. It returns the new number of elements in the array. Syntax array_unshift ( array &$array [, mixed $... ] ) Parameter array(required)- This array represents...

1 minute read.

Python if-else

Python if-else The else statement is associated with if statement. An else statement executes if the conditional expression in if the statement becomes false or a Zero value. If the conditional expression...

2 minutes read.

PHP array_change_key_case() Function

PHP array_change_key_case() Function The array_change_key_case() function in PHP is used to change the case of all keys present in the specified array. It returns an array with all keys in the specified array to lowercase or...

1 minute read.

PHP is_object() Function

The is_ object() function in PHP finds whether the specified variable is an object or not. It returns a Boolean value TRUE if the specified var is an object else it returns FALSE. Syntax is_object(mixed$var) var(required)- This parameter represents the...

1 minute read.

PHP Arrays

PHP Array is usedto hold more than one value at a time.  In another words, we can say that an array stores multiple values in one single variable. Following are the...

2 minutes read.

PHP array_reverse() Function

PHP array_reverse() Function The array_reverse() function in PHP returns a new array with the elements in the reversed order. Syntax array_reverse (array $array [, bool $preserve_keys = FALSE ] ) Parameter array(required)- This parameter represents the input array preserve_keys (optional)- This parameter specifies if the function should preserve the keys...

1 minute read.

PHP similar_text() Function

PHP similar_text() Function The similar_text() function in PHP calculates the similarity between two strings. Syntax similar_text ( string $first , string $second [, float &$percent ] ) Parameter first(required): This parameter represents the first string to be compared. second(required): This parameter represents the second string to be compared. percent(optional): This...

1 minute read.

PHP array_pop() Function

PHP array_pop() Function The array_pop() function in PHP pops or removes the last element from the array shortening the array by one element. Syntax array_pop ( array &$array ) Parameter array(required)- This parameter represents the input array to get the value...

1 minute read.

PHP Include Function

PHP Include( ) The PHP include() statement holds all the code/text that liesin the defined file and paste it into the file that uses the "include" statement. With the help of include...

3 minutes read.

PHP Functions

PHP functions are used to reuse piece of code many times.  There are various built-in functions in PHP. A function will be executed by a call to the function. Following are...

3 minutes read.

PHP fprintf() Function

PHP fprintf() Function The fprintf() function in PHP outputs a formatted string. This function operates as printf() but accepts an array of arguments, rather than a variable number of arguments. Syntax vprintf ( string $format , array $args ) Parameter format(required)- This parameter specifies the string and how to...

4 minutes read.

PHP Indexed Array

In PHP, arrays are linear data structures that allow to store multiple elements of the same type under a single variable which helps in saving the time and effort of...

3 minutes read.

PHP quoted_printable_encode() Function

PHP quoted_printable_encode() Function The quoted_printable_encode() function in PHP converts a 8 bit string to a quoted-printable string. This function is similar to imap_8bit(), except this one does not require the IMAP module to work. Syntax quoted_printable_encode ( string $str ) Parameter str(required)- This parameter represents...

1 minute read.

PHP foreach Loop

PHP foreach Loop with Example PHP foreach loop is used to loop through the associative arrays. Syntax: foreach($array as $key => $value) { //Statement } $array = associative array. $key = array key. &value =...

2 minutes read.

PHP array_fill_keys() Function

The array_fill_keys() function in PHP fills an array with the value of the specified value parameter, using the values of the specified keys array as keys. Syntax array_fill_keys ( array $keys , mixed $value ) Parameter keys(required)- This parameter signifies the input array of values that will be...

1 minute read.