2 /* Prototype : bool usort(array $array_arg, string $cmp_function)
3 * Description: Sort an array by values using a user-defined comparison function
4 * Source code: ext/standard/array.c
8 * Pass different data types as $array_arg argument to usort() to test behaviour
11 echo "*** Testing usort() : usage variations ***\n";
13 // Initialise function arguments not being substituted
14 function cmp_function($value1, $value2)
16 if($value1 == $value2) {
19 else if($value1 > $value2) {
27 //get an unset variable
34 public function __toString() {
35 return "Class A object";
44 // get a resource variable
45 $fp = fopen(__FILE__
, "r");
47 // unexpected values to be passed to $array_arg argument
87 /*23*/ @$undefined_var,
96 // loop through each element of $inputs to check the behavior of usort()
98 foreach($inputs as $input) {
99 echo "\n-- Iteration $iterator --\n";
100 var_dump( usort($input, 'cmp_function') );