2 /* Prototype : bool array_multisort(array ar1 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING|SORT_NATURAL|SORT_FLAG_CASE]] [, array ar2 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING|SORT_NATURAL|SORT_FLAG_CASE]], ...])
3 * Description: Sort multiple arrays at once similar to how ORDER BY clause works in SQL
4 * Source code: ext/standard/array.c
8 echo "*** Testing array_multisort() : usage variation ***\n";
10 // Define error handler
11 function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
12 if (error_reporting() != 0) {
13 // report non-silenced errors
14 echo "Error: $err_no - $err_msg, $filename($linenum)\n";
17 set_error_handler('test_error_handler');
19 // Initialise function arguments not being substituted (if any)
23 //get an unset variable
27 // define some classes
28 class classWithToString
30 public function __toString() {
31 return "Class A object";
35 class classWithoutToString
45 $index_array = array (1, 2, 3);
46 $assoc_array = array ('one' => 1, 'two' => 2);
48 //array of values to iterate over
55 'int -12345' => -2345,
59 'float -10.5' => -10.5,
60 'float 12.3456789000e10' => 12.3456789000e10
,
61 'float -12.3456789000e10' => -12.3456789000e10
,
65 'empty array' => array(),
66 'int indexed array' => $index_array,
67 'associative array' => $assoc_array,
68 'nested arrays' => array('foo', $index_array, $assoc_array),
71 'uppercase NULL' => NULL,
72 'lowercase null' => null,
75 'lowercase true' => true,
76 'lowercase false' =>false,
77 'uppercase TRUE' =>TRUE,
78 'uppercase FALSE' =>FALSE,
81 'empty string DQ' => "",
82 'empty string SQ' => '',
85 'string DQ' => "string",
86 'string SQ' => 'string',
87 'mixed case string' => "sTrInG",
88 'heredoc' => $heredoc,
91 'instance of classWithToString' => new classWithToString(),
92 'instance of classWithoutToString' => new classWithoutToString(),
95 'undefined var' => @$undefined_var,
98 'unset var' => @$unset_var,
101 // loop through each element of the array for SORT_REGULAR|SORT_NUMERIC|SORT_STRING|SORT_NATURAL|SORT_FLAG_CASE]]
103 foreach($inputs as $key =>$value) {
105 var_dump( array_multisort($ar1, $value) );