import zend standard tests
[hiphop-php.git] / hphp / test / zend / good / ext-standard-array / krsort_variation3.php
blob7ee113c566eb4f15db48b9419f3715875dc87e33
1 <?php
2 /* Prototype : bool krsort ( array &$array [, int $sort_flags] )
3 * Description: Sort an array by key in reverse order, maintaining key to data correlation
4 * Source code: ext/standard/array.c
5 */
7 /*
8 * Testing krsort() by providing array of integer/float/mixed values for $array argument
9 * with following flag values:
10 * 1.flag value as defualt
11 * 2.SORT_REGULAR - compare items normally
12 * 3.SORT_NUMERIC - compare items numerically
15 echo "*** Testing krsort() : usage variations ***\n";
17 // diff. associative arrays to sort
18 $various_arrays = array(
19 // negative/posative integer key value array
20 array(1 => 11, -2 => -11, 3 => 21, -4 => -21, 5 => 31, -6 => -31, 7 => 0, 8 => 41, -10 =>-41),
22 // float key values
23 array(1.0 => 10.5, 0.2 => -10.5, 3.1 => 10.5e2, 4 => 10.6E-2, .5 => .5, 6 => .0001, -7 => -.1),
25 // mixed value array with different types of keys
26 array(1 => .0001, 2 => .0021, -3 => -.01, 4 => -1, 5 => 0, 6 => .09, 7 => 2, -8 => -.9, 9 => 10.6E-2,
27 -10 => -10.6E-2, 11 => 33)
30 // set of possible flag values
31 $flags = array("SORT_REGULAR" => SORT_REGULAR, "SORT_NUMERIC" => SORT_NUMERIC);
33 $count = 1;
34 echo "\n-- Testing krsort() by supplying various integer/float arrays --\n";
36 // loop through to test krsort() with different arrays
37 foreach ($various_arrays as $array) {
38 echo "\n-- Iteration $count --\n";
40 echo "- With defualt sort flag -\n";
41 $temp_array = $array;
42 var_dump(krsort($temp_array) );
43 var_dump($temp_array);
45 // loop through $flags array and call krsort() with all possible sort flag values
46 foreach($flags as $key => $flag){
47 echo "- Sort flag = $key -\n";
48 $temp_array = $array;
49 var_dump(krsort($temp_array, $flag) );
50 var_dump($temp_array);
52 $count++;
55 echo "Done\n";