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 empty() Function

PHP empty() Function The empty() function in PHP determines whether the specified variable is empty or not. The specified variable is considered empty if it does not exist or if its value is equal to FALSE. This function...

1 minute 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 key_exists() Function

PHP key_exists() Function The key_exists() function in PHP checks if the specified key or index exists in the array or not. Syntax key_exists ( mixed $key , array $array )  Parameter key(required)- This parameter represents the value to check. array(required)- This parameter signifies an input array with...

1 minute read.

PHP Tutorial

PHP Tutorial PHP Introduction PHP is a server-side scripting language which is used for web development. It stands for Hypertext Preprocessor. It is faster than another programming language. It supports multiple databases like MySQL, SQL, PostgreSQL and...

3 minutes 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 array_map() Function

PHP array_map() Function The array_map() function  in PHP is used to return an array containing the results of applying the user-defined callback function over the elements of one or more arrays. Syntax array_map ( callable $callback , array $array1 [, array $... ] )  Parameter callable(required)- This parameter...

1 minute read.

PHP String

PHP string is a sequence of characters. It is used to store and manipulate text. We can specify a string literal in four ways: single quoted double quoted heredoc syntax ...

2 minutes read.

PHP count() function

PHP count() function The count() function in PHP is used to count all elements in the specified array or something in an object. Syntax count ( mixed $array_or_countable [, int $mode = COUNT_NORMAL ] )   Parameter array_or_countable(required)– This parameter represents the input array or countable object. mode(optional)- This...

2 minutes read.

PHP htmlspecialchars_decode() Function

PHP htmlspecialchars_decode() Function The htmlspecialchars_decode() function in PHP convert some predefined HTML entities to characters. The some predefined HTML entities that will be decoded are as follows: & OR & (ampersand)" OR " (double quote)'...

2 minutes read.

PHP array_splice() Function

PHP array_splice() Function The array_splice() function in PHP is used to remove a portion of the array and replaces them with the elements of the replacement array. Syntax array_splice (array &$input, int $offset [, int $length = count($input) [, mixed $replacement = array() ]] ) Parameter input(required)- This array represents the...

2 minutes read.

PHP chunk_split() Function

PHP chunk_split() Function The chunk_split() function in PHP splits a string into a series of smaller parts. Syntax chunk_split(string,length,end) Parameter string(required)- It specifies the string to split. length(optional)- This parameter represents a number that defines the...

1 minute read.

PHP Data Types

PHP data type is used to hold the various types of data or value.  There are three types of data types in PHP. It is a loosely data typed language, so...

2 minutes read.

PHP Super Global Variables

There are various predefine “superglobals” in PHP. These variables can easily accessible in function or class. Following are the superglobals variables: $GLOBALS $_SERVER $_REQUEST $_POST $_GETetc. PHP $GLOBALS The “$GLOBAL” isa keyword that...

2 minutes read.

PHP Variables

PHP Variable is the name of memory location used to hold the data.  In PHP, variable starts with $ symbol. Rules for PHP Variables. Variable starts with $ sign. Variable name...

2 minutes read.

PHP stripos() Function

PHP stripos() Function The stripos() function in PHP finds the position of the first occurrence of a substring in the specified string. It is a case-insensitive a binary-safe function. The related functions are as follows: strripos() Functionstrpos() Functionstrrpos() Function Syntax stripos ( string $haystack , mixed $needle [, int $offset...

1 minute 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.

PHP sha1() Function

PHP sha1() Function The sha1() in PHP calculates the SHA-1 hash of a string. Syntax sha1 ( string $str [, bool $raw_output = FALSE ] )  Parameter str (required)- This parameter represents the input string. raw_output(optional)- This parameter takes Boolean value and returns the digest in raw binary format...

1 minute 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_replace() Function

PHP array_replace() Function The array_replace() function in PHP replaces the elements from passed arrays into the first array with values having the same keys in each of the following arrays. Syntax array_replace ( array $array1 [, array $... ] ) Parameter array(required)- This parameter represents...

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.