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');
21 //get an unset variable
25 // define some classes
26 class classWithToString
28 public function __toString() {
29 return "Class A object";
33 class classWithoutToString
43 $index_array = array (1, 2, 3);
44 $assoc_array = array ('one' => 1, 'two' => 2);
46 //array of values to iterate over
53 'int -12345' => -2345,
57 'float -10.5' => -10.5,
58 'float 12.3456789000e10' => 12.3456789000e10
,
59 'float -12.3456789000e10' => -12.3456789000e10
,
63 'uppercase NULL' => NULL,
64 'lowercase null' => null,
67 'lowercase true' => true,
68 'lowercase false' =>false,
69 'uppercase TRUE' =>TRUE,
70 'uppercase FALSE' =>FALSE,
73 'empty string DQ' => "",
74 'empty string SQ' => '',
77 'string DQ' => "string",
78 'string SQ' => 'string',
79 'mixed case string' => "sTrInG",
80 'heredoc' => $heredoc,
83 'instance of classWithToString' => new classWithToString(),
84 'instance of classWithoutToString' => new classWithoutToString(),
87 'undefined var' => @$undefined_var,
90 'unset var' => @$unset_var,
93 // loop through each element of the array for ar1
95 foreach($inputs as $key =>$value) {
97 var_dump( array_multisort($value));