--- /dev/null
+--TEST--
+Test krsort() function : basic functionality
+--FILE--
+<?php
+/* Prototype : bool krsort ( array &$array [, int $sort_flags] )
+ * Description: Sort an array by key in reverse order, maintaining key to data correlation
+ * Source code: ext/standard/array.c
+*/
+
+/*
+ * Testing krsort() by providing array of integer/string values to check the basic functionality
+ * with following flag values :
+ * 1.flag value as defualt
+ * 2.SORT_REGULAR - compare items normally
+ * 3.SORT_NUMERIC - compare items numerically
+ * 4.SORT_STRING - compare items as strings
+*/
+
+echo "*** Testing krsort() : basic functionality ***\n";
+
+// an array containing unsorted string values with indices
+$unsorted_strings = array( "lemon" => "l", "orange" => "o", "banana" => "b" );
+// an array containing unsorted numeric values with indices
+$unsorted_numerics = array( 100 => 4, 33 => 3, 555 => 2, 22 => 1 );
+
+echo "\n-- Testing krsort() by supplying string array, 'flag' value is defualt --\n";
+$temp_array = $unsorted_strings;
+var_dump( krsort($temp_array) ); // expecting : bool(true)
+var_dump( $temp_array);
+
+echo "\n-- Testing krsort() by supplying numeric array, 'flag' value is defualt --\n";
+$temp_array = $unsorted_numerics;
+var_dump( krsort($temp_array) ); // expecting : bool(true)
+var_dump( $temp_array);
+
+echo "\n-- Testing krsort() by supplying string array, 'flag' = SORT_REGULAR --\n";
+$temp_array = $unsorted_strings;
+var_dump( krsort($temp_array, SORT_REGULAR) ); // expecting : bool(true)
+var_dump( $temp_array);
+
+echo "\n-- Testing krsort() by supplying numeric array, 'flag' = SORT_REGULAR --\n";
+$temp_array = $unsorted_numerics;
+var_dump( krsort($temp_array, SORT_REGULAR) ); // expecting : bool(true)
+var_dump( $temp_array);
+
+echo "\n-- Testing krsort() by supplying string array, 'flag' = SORT_STRING --\n";
+$temp_array = $unsorted_strings;
+var_dump( krsort($temp_array, SORT_STRING) ); // expecting : bool(true)
+var_dump( $temp_array);
+
+echo "\n-- Testing krsort() by supplying numeric array, 'flag' = SORT_NUMERIC --\n";
+$temp_array = $unsorted_numerics;
+var_dump( krsort($temp_array, SORT_NUMERIC) ); // expecting : bool(true)
+var_dump( $temp_array);
+
+echo "Done\n";
+?>
+--EXPECTF--
+*** Testing krsort() : basic functionality ***
+
+-- Testing krsort() by supplying string array, 'flag' value is defualt --
+bool(true)
+array(3) {
+ ["orange"]=>
+ string(1) "o"
+ ["lemon"]=>
+ string(1) "l"
+ ["banana"]=>
+ string(1) "b"
+}
+
+-- Testing krsort() by supplying numeric array, 'flag' value is defualt --
+bool(true)
+array(4) {
+ [555]=>
+ int(2)
+ [100]=>
+ int(4)
+ [33]=>
+ int(3)
+ [22]=>
+ int(1)
+}
+
+-- Testing krsort() by supplying string array, 'flag' = SORT_REGULAR --
+bool(true)
+array(3) {
+ ["orange"]=>
+ string(1) "o"
+ ["lemon"]=>
+ string(1) "l"
+ ["banana"]=>
+ string(1) "b"
+}
+
+-- Testing krsort() by supplying numeric array, 'flag' = SORT_REGULAR --
+bool(true)
+array(4) {
+ [555]=>
+ int(2)
+ [100]=>
+ int(4)
+ [33]=>
+ int(3)
+ [22]=>
+ int(1)
+}
+
+-- Testing krsort() by supplying string array, 'flag' = SORT_STRING --
+bool(true)
+array(3) {
+ ["orange"]=>
+ string(1) "o"
+ ["lemon"]=>
+ string(1) "l"
+ ["banana"]=>
+ string(1) "b"
+}
+
+-- Testing krsort() by supplying numeric array, 'flag' = SORT_NUMERIC --
+bool(true)
+array(4) {
+ [555]=>
+ int(2)
+ [100]=>
+ int(4)
+ [33]=>
+ int(3)
+ [22]=>
+ int(1)
+}
+Done
--- /dev/null
+--TEST--
+Test krsort() function : error conditions
+--FILE--
+<?php
+/* Prototype : bool krsort(array &array_arg [, int asort_flags])
+ * Description: Sort an array
+ * Source code: ext/standard/array.c
+*/
+
+/*
+* Testing krsort() function with all possible error conditions
+*/
+
+echo "*** Testing krsort() : error conditions ***\n";
+
+// Zero arguments
+echo "\n-- Testing krsort() function with zero arguments --\n";
+var_dump( krsort() );
+
+//Test krsort with more than the expected number of arguments
+echo "\n-- Testing krsort() function with more than expected no. of arguments --\n";
+$array_arg = array(1 => 1, 2 => 2);
+$flags = array("SORT_REGULAR" => SORT_REGULAR, "SORT_STRING" => SORT_STRING, "SORT_NUMERIC" => SORT_NUMERIC);
+$extra_arg = 10;
+
+// loop through $flag_value array and call krsort with all possible sort flag values
+foreach($flags as $key => $flag){
+ echo "\n- Sort flag = $key -\n";
+ $temp_array = $array_arg;
+ var_dump( krsort($temp_array,$flag, $extra_arg) );
+ var_dump($temp_array);
+}
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing krsort() : error conditions ***
+
+-- Testing krsort() function with zero arguments --
+
+Warning: krsort() expects at least 1 parameter, 0 given in %s on line %d
+bool(false)
+
+-- Testing krsort() function with more than expected no. of arguments --
+
+- Sort flag = SORT_REGULAR -
+
+Warning: krsort() expects at most 2 parameters, 3 given in %s on line %d
+bool(false)
+array(2) {
+ [1]=>
+ int(1)
+ [2]=>
+ int(2)
+}
+
+- Sort flag = SORT_STRING -
+
+Warning: krsort() expects at most 2 parameters, 3 given in %s on line %d
+bool(false)
+array(2) {
+ [1]=>
+ int(1)
+ [2]=>
+ int(2)
+}
+
+- Sort flag = SORT_NUMERIC -
+
+Warning: krsort() expects at most 2 parameters, 3 given in %s on line %d
+bool(false)
+array(2) {
+ [1]=>
+ int(1)
+ [2]=>
+ int(2)
+}
+Done
--- /dev/null
+--TEST--
+Test krsort() function : object functionality - sort objects
+--FILE--
+<?php
+/* Prototype : bool krsort ( array &$array [, int $sort_flags] )
+ * Description: Sort an array by key in reverse order, maintaining key to data correlation
+ * Source code: ext/standard/array.c
+*/
+/*
+ * testing krsort() by providing array of integer/string objects with following flag values:
+ * 1.Defualt flag value
+ * 2.SORT_REGULAR - compare items normally
+*/
+
+echo "*** Testing krsort() : object functionality ***\n";
+
+// class declaration for integer objects
+class Integer
+{
+ public $class_value;
+ // initializing object member value
+ function __construct($value){
+ $this->class_value = $value;
+ }
+}
+
+// class declaration for string objects
+class String
+{
+ public $class_value;
+ // initializing object member value
+ function __construct($value){
+ $this->class_value = $value;
+ }
+
+ // return string value
+ function __tostring() {
+ return (string)$this->value;
+ }
+
+}
+
+// array of integer objects with different key values
+$unsorted_int_obj = array (
+ 10 => new Integer(11), 20 => new Integer(66),
+ 3 => new Integer(23), 4 => new Integer(-5),
+ 50 => new Integer(0.001), 6 => new Integer(0)
+);
+
+// array of string objects with different key values
+$unsorted_str_obj = array (
+ "axx" => new String("axx"), "t" => new String("t"),
+ "w" => new String("w"), "py" => new String("py"),
+ "apple" => new String("apple"), "Orange" => new String("Orange"),
+ "Lemon" => new String("Lemon"), "aPPle" => new String("aPPle")
+);
+
+
+echo "\n-- Testing krsort() by supplying various object arrays, 'flag' value is defualt --\n";
+
+// testing krsort() function by supplying integer object array, flag value is defualt
+$temp_array = $unsorted_int_obj;
+var_dump(krsort($temp_array) );
+var_dump($temp_array);
+
+// testing krsort() function by supplying string object array, flag value is defualt
+$temp_array = $unsorted_str_obj;
+var_dump(krsort($temp_array) );
+var_dump($temp_array);
+
+echo "\n-- Testing krsort() by supplying various object arrays, 'flag' value is SORT_REGULAR --\n";
+// testing krsort() function by supplying integer object array, flag value = SORT_REGULAR
+$temp_array = $unsorted_int_obj;
+var_dump(krsort($temp_array, SORT_REGULAR) );
+var_dump($temp_array);
+
+// testing krsort() function by supplying string object array, flag value = SORT_REGULAR
+$temp_array = $unsorted_str_obj;
+var_dump(krsort($temp_array, SORT_REGULAR) );
+var_dump($temp_array);
+
+echo "Done\n";
+?>
+--EXPECTF--
+*** Testing krsort() : object functionality ***
+
+-- Testing krsort() by supplying various object arrays, 'flag' value is defualt --
+bool(true)
+array(6) {
+ [50]=>
+ object(Integer)#%d (1) {
+ ["class_value"]=>
+ float(0.001)
+ }
+ [20]=>
+ object(Integer)#%d (1) {
+ ["class_value"]=>
+ int(66)
+ }
+ [10]=>
+ object(Integer)#%d (1) {
+ ["class_value"]=>
+ int(11)
+ }
+ [6]=>
+ object(Integer)#%d (1) {
+ ["class_value"]=>
+ int(0)
+ }
+ [4]=>
+ object(Integer)#%d (1) {
+ ["class_value"]=>
+ int(-5)
+ }
+ [3]=>
+ object(Integer)#%d (1) {
+ ["class_value"]=>
+ int(23)
+ }
+}
+bool(true)
+array(8) {
+ ["w"]=>
+ object(String)#%d (1) {
+ ["class_value"]=>
+ string(1) "w"
+ }
+ ["t"]=>
+ object(String)#%d (1) {
+ ["class_value"]=>
+ string(1) "t"
+ }
+ ["py"]=>
+ object(String)#%d (1) {
+ ["class_value"]=>
+ string(2) "py"
+ }
+ ["axx"]=>
+ object(String)#%d (1) {
+ ["class_value"]=>
+ string(3) "axx"
+ }
+ ["apple"]=>
+ object(String)#%d (1) {
+ ["class_value"]=>
+ string(5) "apple"
+ }
+ ["aPPle"]=>
+ object(String)#%d (1) {
+ ["class_value"]=>
+ string(5) "aPPle"
+ }
+ ["Orange"]=>
+ object(String)#%d (1) {
+ ["class_value"]=>
+ string(6) "Orange"
+ }
+ ["Lemon"]=>
+ object(String)#%d (1) {
+ ["class_value"]=>
+ string(5) "Lemon"
+ }
+}
+
+-- Testing krsort() by supplying various object arrays, 'flag' value is SORT_REGULAR --
+bool(true)
+array(6) {
+ [50]=>
+ object(Integer)#%d (1) {
+ ["class_value"]=>
+ float(0.001)
+ }
+ [20]=>
+ object(Integer)#%d (1) {
+ ["class_value"]=>
+ int(66)
+ }
+ [10]=>
+ object(Integer)#%d (1) {
+ ["class_value"]=>
+ int(11)
+ }
+ [6]=>
+ object(Integer)#%d (1) {
+ ["class_value"]=>
+ int(0)
+ }
+ [4]=>
+ object(Integer)#%d (1) {
+ ["class_value"]=>
+ int(-5)
+ }
+ [3]=>
+ object(Integer)#%d (1) {
+ ["class_value"]=>
+ int(23)
+ }
+}
+bool(true)
+array(8) {
+ ["w"]=>
+ object(String)#%d (1) {
+ ["class_value"]=>
+ string(1) "w"
+ }
+ ["t"]=>
+ object(String)#%d (1) {
+ ["class_value"]=>
+ string(1) "t"
+ }
+ ["py"]=>
+ object(String)#%d (1) {
+ ["class_value"]=>
+ string(2) "py"
+ }
+ ["axx"]=>
+ object(String)#%d (1) {
+ ["class_value"]=>
+ string(3) "axx"
+ }
+ ["apple"]=>
+ object(String)#%d (1) {
+ ["class_value"]=>
+ string(5) "apple"
+ }
+ ["aPPle"]=>
+ object(String)#%d (1) {
+ ["class_value"]=>
+ string(5) "aPPle"
+ }
+ ["Orange"]=>
+ object(String)#%d (1) {
+ ["class_value"]=>
+ string(6) "Orange"
+ }
+ ["Lemon"]=>
+ object(String)#%d (1) {
+ ["class_value"]=>
+ string(5) "Lemon"
+ }
+}
+Done
--- /dev/null
+--TEST--
+Test krsort() function : usage variations - unexpected values for 'array' argument
+--FILE--
+<?php
+/* Prototype : bool krsort(array &array_arg [, int sort_flags])
+ * Description: Sort an array by key in reverse order, maintaining key to data correlation
+ * Source code: ext/standard/array.c
+*/
+
+/*
+ * testing krsort() by providing different unexpected values for array argument
+ * with following flag values:
+ * 1.flag value as defualt
+ * 2.SORT_REGULAR - compare items normally
+ * 3.SORT_NUMERIC - compare items numerically
+ * 4.SORT_STRING - compare items as strings
+*/
+
+echo "*** Testing krsort() : usage variations ***\n";
+
+// get an unset variable
+$unset_var = 10;
+unset ($unset_var);
+
+// resource variable
+$fp = fopen(__FILE__, "r");
+
+$unexpected_values = array (
+
+ // int data
+/*1*/ 0,
+ 1,
+ 12345,
+ -2345,
+
+ // float data
+/*5*/ 10.5,
+ -10.5,
+ 10.5e3,
+ 10.6E-2,
+ 0.5,
+
+ // null data
+/*10*/ NULL,
+ null,
+
+ // boolean data
+/*11*/ true,
+ false,
+ TRUE,
+ FALSE,
+
+ // empty data
+/*15*/ "",
+ '',
+
+ // string data
+/*17*/ "string",
+ 'string',
+
+ // object data
+/*19*/ new stdclass(),
+
+ // undefined data
+/*20*/ @undefined_var,
+
+ // unset data
+/*21*/ @unset_var,
+
+ // resource variable
+/*22*/ $fp
+);
+
+// loop though each element of the array and check the working of krsort()
+// when $array arugment is supplied with different values from $unexpected_values
+echo "\n-- Testing krsort() by supplying different unexpected values for 'array' argument --\n";
+echo "\n-- Flag values are defualt, SORT_REGULAR, SORT_NUMERIC, SORT_STRING --\n";
+
+$counter = 1;
+for($index = 0; $index < count($unexpected_values); $index ++) {
+ echo "-- Iteration $counter --\n";
+ $value = $unexpected_values [$index];
+ var_dump( krsort($value) ); // expecting : bool(false)
+ var_dump( krsort($value, SORT_REGULAR) ); // expecting : bool(false)
+ var_dump( krsort($value, SORT_NUMERIC) ); // expecting : bool(false)
+ var_dump( krsort($value, SORT_STRING) ); // expecting : bool(false)
+ $counter++;
+}
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing krsort() : usage variations ***
+
+-- Testing krsort() by supplying different unexpected values for 'array' argument --
+
+-- Flag values are defualt, SORT_REGULAR, SORT_NUMERIC, SORT_STRING --
+-- Iteration 1 --
+
+Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d
+bool(false)
+-- Iteration 2 --
+
+Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d
+bool(false)
+-- Iteration 3 --
+
+Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d
+bool(false)
+-- Iteration 4 --
+
+Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d
+bool(false)
+-- Iteration 5 --
+
+Warning: krsort() expects parameter 1 to be array, double given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, double given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, double given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, double given in %s on line %d
+bool(false)
+-- Iteration 6 --
+
+Warning: krsort() expects parameter 1 to be array, double given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, double given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, double given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, double given in %s on line %d
+bool(false)
+-- Iteration 7 --
+
+Warning: krsort() expects parameter 1 to be array, double given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, double given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, double given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, double given in %s on line %d
+bool(false)
+-- Iteration 8 --
+
+Warning: krsort() expects parameter 1 to be array, double given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, double given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, double given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, double given in %s on line %d
+bool(false)
+-- Iteration 9 --
+
+Warning: krsort() expects parameter 1 to be array, double given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, double given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, double given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, double given in %s on line %d
+bool(false)
+-- Iteration 10 --
+
+Warning: krsort() expects parameter 1 to be array, null given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, null given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, null given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, null given in %s on line %d
+bool(false)
+-- Iteration 11 --
+
+Warning: krsort() expects parameter 1 to be array, null given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, null given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, null given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, null given in %s on line %d
+bool(false)
+-- Iteration 12 --
+
+Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d
+bool(false)
+-- Iteration 13 --
+
+Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d
+bool(false)
+-- Iteration 14 --
+
+Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d
+bool(false)
+-- Iteration 15 --
+
+Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d
+bool(false)
+-- Iteration 16 --
+
+Warning: krsort() expects parameter 1 to be array, string given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, string given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, string given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, string given in %s on line %d
+bool(false)
+-- Iteration 17 --
+
+Warning: krsort() expects parameter 1 to be array, string given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, string given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, string given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, string given in %s on line %d
+bool(false)
+-- Iteration 18 --
+
+Warning: krsort() expects parameter 1 to be array, string given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, string given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, string given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, string given in %s on line %d
+bool(false)
+-- Iteration 19 --
+
+Warning: krsort() expects parameter 1 to be array, string given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, string given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, string given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, string given in %s on line %d
+bool(false)
+-- Iteration 20 --
+
+Warning: krsort() expects parameter 1 to be array, object given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, object given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, object given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, object given in %s on line %d
+bool(false)
+-- Iteration 21 --
+
+Warning: krsort() expects parameter 1 to be array, string given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, string given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, string given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, string given in %s on line %d
+bool(false)
+-- Iteration 22 --
+
+Warning: krsort() expects parameter 1 to be array, string given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, string given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, string given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, string given in %s on line %d
+bool(false)
+-- Iteration 23 --
+
+Warning: krsort() expects parameter 1 to be array, resource given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, resource given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, resource given in %s on line %d
+bool(false)
+
+Warning: krsort() expects parameter 1 to be array, resource given in %s on line %d
+bool(false)
+Done
--- /dev/null
+--TEST--
+Test krsort() function : usage variations - sort heredoc strings
+--FILE--
+<?php
+/* Prototype : bool krsort ( array &$array [, int $sort_flags] )
+ * Description: Sort an array by key in reverse order, maintaining key to data correlation
+ * Source code: ext/standard/array.c
+*/
+
+/*
+ * testing krsort() by providing array of heredoc strings for $array argument with
+ * following flag values:
+ * 1.flag value as defualt
+ * 2.SORT_REGULAR - compare items normally
+ * 3.SORT_STRING - compare items as strings
+*/
+
+echo "*** Testing krsort() : usage variations ***\n";
+
+// Different heredoc strings to be sorted
+$simple_heredoc1 =<<<EOT
+Heredoc
+EOT;
+
+$simple_heredoc2 =<<<EOT
+HEREDOC
+EOT;
+
+$multiline_heredoc =<<<EOT
+heredoc string\twith!@# and 123
+Test this!!!
+EOT;
+
+$array = array (
+ $simple_heredoc1 => "Heredoc",
+ $simple_heredoc2 => "HEREDOC",
+ $multiline_heredoc => "heredoc string\twith!@# and 123\nTest this!!!"
+);
+
+echo "\n-- Testing krsort() by supplying heredoc string array, 'flag' value is defualt --\n";
+$temp_array = $array;
+var_dump(krsort($temp_array) ); // expecting : bool(true)
+var_dump($temp_array);
+
+echo "\n-- Testing krsort() by supplying heredoc string array, 'flag' = SORT_REGULAR --\n";
+$temp_array = $array;
+var_dump(krsort($temp_array, SORT_REGULAR) ); // expecting : bool(true)
+var_dump($temp_array);
+
+echo "\n-- Testing krsort() by supplying heredoc string array, 'flag' = SORT_STRING --\n";
+$temp_array = $array;
+var_dump(krsort($temp_array, SORT_STRING) ); // expecting : bool(true)
+var_dump($temp_array);
+
+echo "Done\n";
+?>
+--EXPECTF--
+*** Testing krsort() : usage variations ***
+
+-- Testing krsort() by supplying heredoc string array, 'flag' value is defualt --
+bool(true)
+array(3) {
+ ["heredoc string with!@# and 123
+Test this!!!"]=>
+ string(43) "heredoc string with!@# and 123
+Test this!!!"
+ ["Heredoc"]=>
+ string(7) "Heredoc"
+ ["HEREDOC"]=>
+ string(7) "HEREDOC"
+}
+
+-- Testing krsort() by supplying heredoc string array, 'flag' = SORT_REGULAR --
+bool(true)
+array(3) {
+ ["heredoc string with!@# and 123
+Test this!!!"]=>
+ string(43) "heredoc string with!@# and 123
+Test this!!!"
+ ["Heredoc"]=>
+ string(7) "Heredoc"
+ ["HEREDOC"]=>
+ string(7) "HEREDOC"
+}
+
+-- Testing krsort() by supplying heredoc string array, 'flag' = SORT_STRING --
+bool(true)
+array(3) {
+ ["heredoc string with!@# and 123
+Test this!!!"]=>
+ string(43) "heredoc string with!@# and 123
+Test this!!!"
+ ["Heredoc"]=>
+ string(7) "Heredoc"
+ ["HEREDOC"]=>
+ string(7) "HEREDOC"
+}
+Done
--- /dev/null
+--TEST--
+Test krsort() function : usage variations - sort bool values
+--FILE--
+<?php
+/* Prototype : bool krsort ( array &$array [, int $sort_flags] )
+ * Description: Sort an array by key in reverse order, maintaining key to data correlation
+ * Source code: ext/standard/array.c
+*/
+
+/*
+ * testing krsort() by providing array of boolean values for $array argument with following flag values:
+ * 1.flag value as defualt
+ * 2.SORT_REGULAR - compare items normally
+*/
+
+echo "*** Testing krsort() : usage variations ***\n";
+
+// bool value array
+$bool_values = array (true => true, false => false, TRUE => TRUE, FALSE => FALSE);
+
+echo "\n-- Testing krsort() by supplying boolean value array, 'flag' value is defualt --\n";
+$temp_array = $bool_values;
+var_dump(krsort($temp_array) );
+var_dump($temp_array);
+
+echo "\n-- Testing krsort() by supplying boolean value array, 'flag' value is SORT_REGULAR --\n";
+$temp_array = $bool_values;
+var_dump(krsort($temp_array, SORT_REGULAR) );
+var_dump($temp_array);
+
+echo "\n-- Testing krsort() by supplying boolean value array, 'flag' value is SORT_NUMERIC --\n";
+$temp_array = $bool_values;
+var_dump(krsort($temp_array, SORT_NUMERIC) );
+var_dump($temp_array);
+
+echo "\n-- Testing krsort() by supplying boolean value array, 'flag' value is SORT_STRING --\n";
+$temp_array = $bool_values;
+var_dump(krsort($temp_array, SORT_STRING) );
+var_dump($temp_array);
+
+echo "Done\n";
+?>
+--EXPECTF--
+*** Testing krsort() : usage variations ***
+
+-- Testing krsort() by supplying boolean value array, 'flag' value is defualt --
+bool(true)
+array(2) {
+ [1]=>
+ bool(true)
+ [0]=>
+ bool(false)
+}
+
+-- Testing krsort() by supplying boolean value array, 'flag' value is SORT_REGULAR --
+bool(true)
+array(2) {
+ [1]=>
+ bool(true)
+ [0]=>
+ bool(false)
+}
+
+-- Testing krsort() by supplying boolean value array, 'flag' value is SORT_NUMERIC --
+bool(true)
+array(2) {
+ [1]=>
+ bool(true)
+ [0]=>
+ bool(false)
+}
+
+-- Testing krsort() by supplying boolean value array, 'flag' value is SORT_STRING --
+bool(true)
+array(2) {
+ [1]=>
+ bool(true)
+ [0]=>
+ bool(false)
+}
+Done
\ No newline at end of file
--- /dev/null
+--TEST--
+Test krsort() function : usage variations - unexpected values for 'sort_flags' argument
+--FILE--
+<?php
+/* Prototype : bool krsort(array &array_arg [, int sort_flags])
+ * Description: Sort an array by key in reverse order, maintaining key to data correlation
+ * Source code: ext/standard/array.c
+*/
+
+/*
+ * Testing krsort() by providing different unexpected values for flag argument
+*/
+
+echo "*** Testing krsort() : usage variations ***\n";
+
+//get an unset variable
+$unset_var = 10;
+unset ($unset_var);
+
+// resource variable
+$fp = fopen(__FILE__, "r");
+
+// an array for checking unexpected behavior
+$unsorted_values = array(10 => 10, 2 => 2, 45 => 45);
+
+//array of unexpected values to iterate over
+$unexpected_values = array (
+
+ // int data
+/*1*/ -2345,
+
+ // float data
+/*2*/ 10.5,
+ -10.5,
+ 10.5e2,
+ 10.6E-2,
+ .5,
+
+ // null data
+/*7*/ NULL,
+ null,
+
+ // boolean data
+/*9*/ true,
+ false,
+ TRUE,
+ FALSE,
+
+ // empty data
+/*13*/ "",
+ '',
+
+ // string data
+/*15*/ "string",
+ 'string',
+
+ // object data
+/*16*/ new stdclass(),
+
+ // undefined data
+/*17*/ @undefined_var,
+
+ // unset data
+/*18*/ @unset_var,
+
+ // resource variable
+/*19*/ $fp
+
+);
+
+// loop though each element of the array and check the working of krsort()
+// when 'sort_flags' arugment is supplied with different values
+echo "\n-- Testing krsort() by supplying different unexpected values for 'sort_flags' argument --\n";
+
+$counter = 1;
+for($index = 0; $index < count($unexpected_values); $index ++) {
+ echo "-- Iteration $counter --\n";
+ $value = $unexpected_values [$index];
+ $temp_array = $unsorted_values;
+ var_dump( krsort($temp_array, $value) );
+ var_dump($temp_array);
+ $counter++;
+}
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing krsort() : usage variations ***
+
+-- Testing krsort() by supplying different unexpected values for 'sort_flags' argument --
+-- Iteration 1 --
+bool(true)
+array(3) {
+ [45]=>
+ int(45)
+ [10]=>
+ int(10)
+ [2]=>
+ int(2)
+}
+-- Iteration 2 --
+bool(true)
+array(3) {
+ [45]=>
+ int(45)
+ [10]=>
+ int(10)
+ [2]=>
+ int(2)
+}
+-- Iteration 3 --
+bool(true)
+array(3) {
+ [45]=>
+ int(45)
+ [10]=>
+ int(10)
+ [2]=>
+ int(2)
+}
+-- Iteration 4 --
+bool(true)
+array(3) {
+ [45]=>
+ int(45)
+ [10]=>
+ int(10)
+ [2]=>
+ int(2)
+}
+-- Iteration 5 --
+bool(true)
+array(3) {
+ [45]=>
+ int(45)
+ [10]=>
+ int(10)
+ [2]=>
+ int(2)
+}
+-- Iteration 6 --
+bool(true)
+array(3) {
+ [45]=>
+ int(45)
+ [10]=>
+ int(10)
+ [2]=>
+ int(2)
+}
+-- Iteration 7 --
+bool(true)
+array(3) {
+ [45]=>
+ int(45)
+ [10]=>
+ int(10)
+ [2]=>
+ int(2)
+}
+-- Iteration 8 --
+bool(true)
+array(3) {
+ [45]=>
+ int(45)
+ [10]=>
+ int(10)
+ [2]=>
+ int(2)
+}
+-- Iteration 9 --
+bool(true)
+array(3) {
+ [45]=>
+ int(45)
+ [10]=>
+ int(10)
+ [2]=>
+ int(2)
+}
+-- Iteration 10 --
+bool(true)
+array(3) {
+ [45]=>
+ int(45)
+ [10]=>
+ int(10)
+ [2]=>
+ int(2)
+}
+-- Iteration 11 --
+bool(true)
+array(3) {
+ [45]=>
+ int(45)
+ [10]=>
+ int(10)
+ [2]=>
+ int(2)
+}
+-- Iteration 12 --
+bool(true)
+array(3) {
+ [45]=>
+ int(45)
+ [10]=>
+ int(10)
+ [2]=>
+ int(2)
+}
+-- Iteration 13 --
+
+Warning: krsort() expects parameter 2 to be long, string given in %s on line %d
+bool(false)
+array(3) {
+ [10]=>
+ int(10)
+ [2]=>
+ int(2)
+ [45]=>
+ int(45)
+}
+-- Iteration 14 --
+
+Warning: krsort() expects parameter 2 to be long, string given in %s on line %d
+bool(false)
+array(3) {
+ [10]=>
+ int(10)
+ [2]=>
+ int(2)
+ [45]=>
+ int(45)
+}
+-- Iteration 15 --
+
+Warning: krsort() expects parameter 2 to be long, string given in %s on line %d
+bool(false)
+array(3) {
+ [10]=>
+ int(10)
+ [2]=>
+ int(2)
+ [45]=>
+ int(45)
+}
+-- Iteration 16 --
+
+Warning: krsort() expects parameter 2 to be long, string given in %s on line %d
+bool(false)
+array(3) {
+ [10]=>
+ int(10)
+ [2]=>
+ int(2)
+ [45]=>
+ int(45)
+}
+-- Iteration 17 --
+
+Warning: krsort() expects parameter 2 to be long, object given in %s on line %d
+bool(false)
+array(3) {
+ [10]=>
+ int(10)
+ [2]=>
+ int(2)
+ [45]=>
+ int(45)
+}
+-- Iteration 18 --
+
+Warning: krsort() expects parameter 2 to be long, string given in %s on line %d
+bool(false)
+array(3) {
+ [10]=>
+ int(10)
+ [2]=>
+ int(2)
+ [45]=>
+ int(45)
+}
+-- Iteration 19 --
+
+Warning: krsort() expects parameter 2 to be long, string given in %s on line %d
+bool(false)
+array(3) {
+ [10]=>
+ int(10)
+ [2]=>
+ int(2)
+ [45]=>
+ int(45)
+}
+-- Iteration 20 --
+
+Warning: krsort() expects parameter 2 to be long, resource given in %s on line %d
+bool(false)
+array(3) {
+ [10]=>
+ int(10)
+ [2]=>
+ int(2)
+ [45]=>
+ int(45)
+}
+Done
--- /dev/null
+--TEST--
+Test krsort() function : usage variations - sort integer/float values
+--FILE--
+<?php
+/* Prototype : bool krsort ( array &$array [, int $sort_flags] )
+ * Description: Sort an array by key in reverse order, maintaining key to data correlation
+ * Source code: ext/standard/array.c
+*/
+
+/*
+ * Testing krsort() by providing array of integer/float/mixed values for $array argument
+ * with following flag values:
+ * 1.flag value as defualt
+ * 2.SORT_REGULAR - compare items normally
+ * 3.SORT_NUMERIC - compare items numerically
+*/
+
+echo "*** Testing krsort() : usage variations ***\n";
+
+// diff. associative arrays to sort
+$various_arrays = array(
+ // negative/posative integer key value array
+ array(1 => 11, -2 => -11, 3 => 21, -4 => -21, 5 => 31, -6 => -31, 7 => 0, 8 => 41, -10 =>-41),
+
+ // float key values
+ array(1.0 => 10.5, 0.2 => -10.5, 3.1 => 10.5e2, 4 => 10.6E-2, .5 => .5, 6 => .0001, -7 => -.1),
+
+ // mixed value array with different types of keys
+ array(1 => .0001, 2 => .0021, -3 => -.01, 4 => -1, 5 => 0, 6 => .09, 7 => 2, -8 => -.9, 9 => 10.6E-2,
+ -10 => -10.6E-2, 11 => 33),
+
+ // array keys contains minimum and maximum ranges
+ array( 2147483647 => 1 , 2147483648 => 2, -2147483647 => 3, -2147483648 => 4, -0 => 5)
+);
+
+// set of possible flag values
+$flags = array("SORT_REGULAR" => SORT_REGULAR, "SORT_NUMERIC" => SORT_NUMERIC);
+
+$count = 1;
+echo "\n-- Testing krsort() by supplying various integer/float arrays --\n";
+
+// loop through to test krsort() with different arrays
+foreach ($various_arrays as $array) {
+ echo "\n-- Iteration $count --\n";
+
+ echo "- With defualt sort flag -\n";
+ $temp_array = $array;
+ var_dump(krsort($temp_array) );
+ var_dump($temp_array);
+
+ // loop through $flags array and call krsort() with all possible sort flag values
+ foreach($flags as $key => $flag){
+ echo "- Sort flag = $key -\n";
+ $temp_array = $array;
+ var_dump(krsort($temp_array, $flag) );
+ var_dump($temp_array);
+ }
+ $count++;
+}
+
+echo "Done\n";
+?>
+--EXPECTF--
+*** Testing krsort() : usage variations ***
+
+-- Testing krsort() by supplying various integer/float arrays --
+
+-- Iteration 1 --
+- With defualt sort flag -
+bool(true)
+array(9) {
+ [8]=>
+ int(41)
+ [7]=>
+ int(0)
+ [5]=>
+ int(31)
+ [3]=>
+ int(21)
+ [1]=>
+ int(11)
+ [-2]=>
+ int(-11)
+ [-4]=>
+ int(-21)
+ [-6]=>
+ int(-31)
+ [-10]=>
+ int(-41)
+}
+- Sort flag = SORT_REGULAR -
+bool(true)
+array(9) {
+ [8]=>
+ int(41)
+ [7]=>
+ int(0)
+ [5]=>
+ int(31)
+ [3]=>
+ int(21)
+ [1]=>
+ int(11)
+ [-2]=>
+ int(-11)
+ [-4]=>
+ int(-21)
+ [-6]=>
+ int(-31)
+ [-10]=>
+ int(-41)
+}
+- Sort flag = SORT_NUMERIC -
+bool(true)
+array(9) {
+ [8]=>
+ int(41)
+ [7]=>
+ int(0)
+ [5]=>
+ int(31)
+ [3]=>
+ int(21)
+ [1]=>
+ int(11)
+ [-2]=>
+ int(-11)
+ [-4]=>
+ int(-21)
+ [-6]=>
+ int(-31)
+ [-10]=>
+ int(-41)
+}
+
+-- Iteration 2 --
+- With defualt sort flag -
+bool(true)
+array(6) {
+ [6]=>
+ float(0.0001)
+ [4]=>
+ float(0.106)
+ [3]=>
+ float(1050)
+ [1]=>
+ float(10.5)
+ [0]=>
+ float(0.5)
+ [-7]=>
+ float(-0.1)
+}
+- Sort flag = SORT_REGULAR -
+bool(true)
+array(6) {
+ [6]=>
+ float(0.0001)
+ [4]=>
+ float(0.106)
+ [3]=>
+ float(1050)
+ [1]=>
+ float(10.5)
+ [0]=>
+ float(0.5)
+ [-7]=>
+ float(-0.1)
+}
+- Sort flag = SORT_NUMERIC -
+bool(true)
+array(6) {
+ [6]=>
+ float(0.0001)
+ [4]=>
+ float(0.106)
+ [3]=>
+ float(1050)
+ [1]=>
+ float(10.5)
+ [0]=>
+ float(0.5)
+ [-7]=>
+ float(-0.1)
+}
+
+-- Iteration 3 --
+- With defualt sort flag -
+bool(true)
+array(11) {
+ [11]=>
+ int(33)
+ [9]=>
+ float(0.106)
+ [7]=>
+ int(2)
+ [6]=>
+ float(0.09)
+ [5]=>
+ int(0)
+ [4]=>
+ int(-1)
+ [2]=>
+ float(0.0021)
+ [1]=>
+ float(0.0001)
+ [-3]=>
+ float(-0.01)
+ [-8]=>
+ float(-0.9)
+ [-10]=>
+ float(-0.106)
+}
+- Sort flag = SORT_REGULAR -
+bool(true)
+array(11) {
+ [11]=>
+ int(33)
+ [9]=>
+ float(0.106)
+ [7]=>
+ int(2)
+ [6]=>
+ float(0.09)
+ [5]=>
+ int(0)
+ [4]=>
+ int(-1)
+ [2]=>
+ float(0.0021)
+ [1]=>
+ float(0.0001)
+ [-3]=>
+ float(-0.01)
+ [-8]=>
+ float(-0.9)
+ [-10]=>
+ float(-0.106)
+}
+- Sort flag = SORT_NUMERIC -
+bool(true)
+array(11) {
+ [11]=>
+ int(33)
+ [9]=>
+ float(0.106)
+ [7]=>
+ int(2)
+ [6]=>
+ float(0.09)
+ [5]=>
+ int(0)
+ [4]=>
+ int(-1)
+ [2]=>
+ float(0.0021)
+ [1]=>
+ float(0.0001)
+ [-3]=>
+ float(-0.01)
+ [-8]=>
+ float(-0.9)
+ [-10]=>
+ float(-0.106)
+}
+
+-- Iteration 4 --
+- With defualt sort flag -
+bool(true)
+array(4) {
+ [2147483647]=>
+ int(1)
+ [0]=>
+ int(5)
+ [-2147483647]=>
+ int(3)
+ [-2147483648]=>
+ int(4)
+}
+- Sort flag = SORT_REGULAR -
+bool(true)
+array(4) {
+ [2147483647]=>
+ int(1)
+ [0]=>
+ int(5)
+ [-2147483647]=>
+ int(3)
+ [-2147483648]=>
+ int(4)
+}
+- Sort flag = SORT_NUMERIC -
+bool(true)
+array(4) {
+ [2147483647]=>
+ int(1)
+ [0]=>
+ int(5)
+ [-2147483647]=>
+ int(3)
+ [-2147483648]=>
+ int(4)
+}
+Done
--- /dev/null
+--TEST--
+Test krsort() function : usage variations - sort octal values
+--FILE--
+<?php
+/* Prototype : bool krsort ( array &$array [, int $sort_flags] )
+ * Description: Sort an array by key in reverse order, maintaining key to data correlation.
+ * Source code: ext/standard/array.c
+*/
+
+/*
+ * testing krsort() by providing array of octal values for $array argument
+ * with following flag values:
+ * 1.flag value as defualt
+ * 2.SORT_REGULAR - compare items normally
+ * 3.SORT_NUMERIC - compare items numerically
+*/
+
+echo "*** Testing krsort() : usage variations ***\n";
+
+// an array containing unsorted octal values
+$unsorted_oct_array = array (
+ 01235 => 01, 0321 => 02, 0345 => 03, 066 => 04, 0772 => 05,
+ 077 => 06, -066 => -01, -0345 => -02, 0 => 0
+);
+
+echo "\n-- Testing krsort() by supplying octal value array, 'flag' value is defualt --\n";
+$temp_array = $unsorted_oct_array;
+var_dump( krsort($temp_array) ); // expecting : bool(true)
+var_dump($temp_array);
+
+echo "\n-- Testing krsort() by supplying octal value array, 'flag' value is SORT_REGULAR --\n";
+$temp_array = $unsorted_oct_array;
+var_dump( krsort($temp_array, SORT_REGULAR) ); // expecting : bool(true)
+var_dump($temp_array);
+
+echo "\n-- Testing krsort() by supplying octal value array, 'flag' value is SORT_NUMERIC --\n";
+$temp_array = $unsorted_oct_array;
+var_dump( krsort($temp_array, SORT_NUMERIC) ); // expecting : bool(true)
+var_dump($temp_array);
+
+echo "Done\n";
+?>
+--EXPECTF--
+*** Testing krsort() : usage variations ***
+
+-- Testing krsort() by supplying octal value array, 'flag' value is defualt --
+bool(true)
+array(9) {
+ [669]=>
+ int(1)
+ [506]=>
+ int(5)
+ [229]=>
+ int(3)
+ [209]=>
+ int(2)
+ [63]=>
+ int(6)
+ [54]=>
+ int(4)
+ [0]=>
+ int(0)
+ [-54]=>
+ int(-1)
+ [-229]=>
+ int(-2)
+}
+
+-- Testing krsort() by supplying octal value array, 'flag' value is SORT_REGULAR --
+bool(true)
+array(9) {
+ [669]=>
+ int(1)
+ [506]=>
+ int(5)
+ [229]=>
+ int(3)
+ [209]=>
+ int(2)
+ [63]=>
+ int(6)
+ [54]=>
+ int(4)
+ [0]=>
+ int(0)
+ [-54]=>
+ int(-1)
+ [-229]=>
+ int(-2)
+}
+
+-- Testing krsort() by supplying octal value array, 'flag' value is SORT_NUMERIC --
+bool(true)
+array(9) {
+ [669]=>
+ int(1)
+ [506]=>
+ int(5)
+ [229]=>
+ int(3)
+ [209]=>
+ int(2)
+ [63]=>
+ int(6)
+ [54]=>
+ int(4)
+ [0]=>
+ int(0)
+ [-54]=>
+ int(-1)
+ [-229]=>
+ int(-2)
+}
+Done
--- /dev/null
+--TEST--
+Test krsort() function : usage variations - sort strings
+--FILE--
+<?php
+/* Prototype : bool krsort ( array &$array [, int $sort_flags] )
+ * Description: Sort an array by key in reverse order, maintaining key to data correlation
+ * Source code: ext/standard/array.c
+*/
+
+/*
+ * testing krsort() by providing array of string values for $array argument with
+ * following flag values:
+ * 1.flag value as defualt
+ * 2.SORT_REGULAR - compare items normally
+ * 3.SORT_STRING - compare items as strings
+*/
+
+echo "*** Testing krsort() : usage variations ***\n";
+
+$various_arrays = array (
+ // diff. escape sequence chars with key values
+ array ( null => null, NULL => NULL, "\a" => "\a", "\cx" => "\cx", "\e" => "\e",
+ "\f" => "\f", "\n" =>"\n", "\r" => "\r", "\t" => "\t", "\xhh" => "\xhh",
+ "\ddd" => "\ddd", "\v" => "\v"
+ ),
+
+ // array containing different strings with key values
+ array ( 'Lemon' => "lemoN", 'o' => "Orange", 'B' => "banana", 'Apple' => "apple", 'te' => "Test",
+ 't' => "TTTT", 'T' => "ttt", 'W' => "ww", 'X' => "x", 'x' => "X", 'O' => "oraNGe",
+ 'B' => "BANANA"
+ )
+);
+
+$flags = array("SORT_REGULAR" => SORT_REGULAR, "SORT_STRING" => SORT_STRING);
+
+$count = 1;
+echo "\n-- Testing krsort() by supplying various string arrays --\n";
+
+// loop through to test krsort() with different arrays
+foreach ($various_arrays as $array) {
+ echo "\n-- Iteration $count --\n";
+
+ echo "- With defualt sort flag -\n";
+ $temp_array = $array;
+ var_dump(krsort($temp_array) ); // expecting : bool(true)
+ var_dump($temp_array);
+
+ // loop through $flags array and call krsort() with all possible sort flag values
+ foreach($flags as $key => $flag){
+ echo "- Sort flag = $key -\n";
+ $temp_array = $array;
+ var_dump(krsort($temp_array, $flag) ); // expecting : bool(true)
+ var_dump($temp_array);
+ }
+ $count++;
+}
+
+echo "Done\n";
+?>
+--EXPECTF--
+*** Testing krsort() : usage variations ***
+
+-- Testing krsort() by supplying various string arrays --
+
+-- Iteration 1 --
+- With defualt sort flag -
+bool(true)
+array(11) {
+ ["\xhh"]=>
+ string(4) "\xhh"
+ ["\e"]=>
+ string(2) "\e"
+ ["\ddd"]=>
+ string(4) "\ddd"
+ ["\cx"]=>
+ string(3) "\cx"
+ ["\a"]=>
+ string(2) "\a"
+ ["
+"]=>
+ string(1) "
+"
+ ["\f"]=>
+ string(1) "\f"
+ ["\v"]=>
+ string(1) "\v"
+ ["
+"]=>
+ string(1) "
+"
+ [" "]=>
+ string(1) " "
+ [""]=>
+ NULL
+}
+- Sort flag = SORT_REGULAR -
+bool(true)
+array(11) {
+ ["\xhh"]=>
+ string(4) "\xhh"
+ ["\e"]=>
+ string(2) "\e"
+ ["\ddd"]=>
+ string(4) "\ddd"
+ ["\cx"]=>
+ string(3) "\cx"
+ ["\a"]=>
+ string(2) "\a"
+ ["
+"]=>
+ string(1) "
+"
+ ["\f"]=>
+ string(1) "\f"
+ ["\v"]=>
+ string(1) "\v"
+ ["
+"]=>
+ string(1) "
+"
+ [" "]=>
+ string(1) " "
+ [""]=>
+ NULL
+}
+- Sort flag = SORT_STRING -
+bool(true)
+array(11) {
+ ["\xhh"]=>
+ string(4) "\xhh"
+ ["\e"]=>
+ string(2) "\e"
+ ["\ddd"]=>
+ string(4) "\ddd"
+ ["\cx"]=>
+ string(3) "\cx"
+ ["\a"]=>
+ string(2) "\a"
+ ["
+"]=>
+ string(1) "
+"
+ ["\f"]=>
+ string(1) "\f"
+ ["\v"]=>
+ string(1) "\v"
+ ["
+"]=>
+ string(1) "
+"
+ [" "]=>
+ string(1) " "
+ [""]=>
+ NULL
+}
+
+-- Iteration 2 --
+- With defualt sort flag -
+bool(true)
+array(11) {
+ ["x"]=>
+ string(1) "X"
+ ["te"]=>
+ string(4) "Test"
+ ["t"]=>
+ string(4) "TTTT"
+ ["o"]=>
+ string(6) "Orange"
+ ["X"]=>
+ string(1) "x"
+ ["W"]=>
+ string(2) "ww"
+ ["T"]=>
+ string(3) "ttt"
+ ["O"]=>
+ string(6) "oraNGe"
+ ["Lemon"]=>
+ string(5) "lemoN"
+ ["B"]=>
+ string(6) "BANANA"
+ ["Apple"]=>
+ string(5) "apple"
+}
+- Sort flag = SORT_REGULAR -
+bool(true)
+array(11) {
+ ["x"]=>
+ string(1) "X"
+ ["te"]=>
+ string(4) "Test"
+ ["t"]=>
+ string(4) "TTTT"
+ ["o"]=>
+ string(6) "Orange"
+ ["X"]=>
+ string(1) "x"
+ ["W"]=>
+ string(2) "ww"
+ ["T"]=>
+ string(3) "ttt"
+ ["O"]=>
+ string(6) "oraNGe"
+ ["Lemon"]=>
+ string(5) "lemoN"
+ ["B"]=>
+ string(6) "BANANA"
+ ["Apple"]=>
+ string(5) "apple"
+}
+- Sort flag = SORT_STRING -
+bool(true)
+array(11) {
+ ["x"]=>
+ string(1) "X"
+ ["te"]=>
+ string(4) "Test"
+ ["t"]=>
+ string(4) "TTTT"
+ ["o"]=>
+ string(6) "Orange"
+ ["X"]=>
+ string(1) "x"
+ ["W"]=>
+ string(2) "ww"
+ ["T"]=>
+ string(3) "ttt"
+ ["O"]=>
+ string(6) "oraNGe"
+ ["Lemon"]=>
+ string(5) "lemoN"
+ ["B"]=>
+ string(6) "BANANA"
+ ["Apple"]=>
+ string(5) "apple"
+}
+Done
--- /dev/null
+--TEST--
+Test krsort() function : usage variations - sort hexadecimal values
+--FILE--
+<?php
+/* Prototype : bool krsort ( array &$array [, int $sort_flags] )
+ * Description: Sort an array by key in reverse order, maintaining key to data correlation.
+ * Source code: ext/standard/array.c
+*/
+
+/*
+ * testing krsort() by providing array of hexa-decimal values for $array argument
+ * with following flag values:
+ * 1.flag value as defualt
+ * 2.SORT_REGULAR - compare items normally
+ * 3.SORT_NUMERIC - compare items numerically
+*/
+
+echo "*** Testing krsort() : usage variations ***\n";
+
+// an array containing unsorted hexadecimal values with keys
+$unsorted_hex_array = array (
+ 0x1AB => 0x1AB, 0xFFF => 0xFFF, 0xF => 0xF, 0xFF => 0xFF, 0x2AA => 0x2AA, 0xBB => 0xBB,
+ 0x1ab => 0x1ab, 0xff => 0xff, -0xff => -0xFF, 0 => 0, -0x2aa => -0x2aa
+);
+
+echo "\n-- Testing krsort() by supplying hexadecimal value array, 'flag' value is defualt --\n";
+$temp_array = $unsorted_hex_array;
+var_dump(krsort( $temp_array) ); // expecting : bool(true)
+var_dump($temp_array);
+
+echo "\n-- Testing krsort() by supplying hexadecimal value array, 'flag' value is SORT_REGULAR --\n";
+$temp_array = $unsorted_hex_array;
+var_dump(krsort( $temp_array, SORT_REGULAR) ); // expecting : bool(true)
+var_dump($temp_array);
+
+echo "\n-- Testing krsort() by supplying hexadecimal value array, 'flag' value is SORT_NUMERIC --\n";
+$temp_array = $unsorted_hex_array;
+var_dump(krsort( $temp_array, SORT_NUMERIC) ); // expecting : bool(true)
+var_dump($temp_array);
+
+echo "Done\n";
+?>
+--EXPECTF--
+*** Testing krsort() : usage variations ***
+
+-- Testing krsort() by supplying hexadecimal value array, 'flag' value is defualt --
+bool(true)
+array(9) {
+ [4095]=>
+ int(4095)
+ [682]=>
+ int(682)
+ [427]=>
+ int(427)
+ [255]=>
+ int(255)
+ [187]=>
+ int(187)
+ [15]=>
+ int(15)
+ [0]=>
+ int(0)
+ [-255]=>
+ int(-255)
+ [-682]=>
+ int(-682)
+}
+
+-- Testing krsort() by supplying hexadecimal value array, 'flag' value is SORT_REGULAR --
+bool(true)
+array(9) {
+ [4095]=>
+ int(4095)
+ [682]=>
+ int(682)
+ [427]=>
+ int(427)
+ [255]=>
+ int(255)
+ [187]=>
+ int(187)
+ [15]=>
+ int(15)
+ [0]=>
+ int(0)
+ [-255]=>
+ int(-255)
+ [-682]=>
+ int(-682)
+}
+
+-- Testing krsort() by supplying hexadecimal value array, 'flag' value is SORT_NUMERIC --
+bool(true)
+array(9) {
+ [4095]=>
+ int(4095)
+ [682]=>
+ int(682)
+ [427]=>
+ int(427)
+ [255]=>
+ int(255)
+ [187]=>
+ int(187)
+ [15]=>
+ int(15)
+ [0]=>
+ int(0)
+ [-255]=>
+ int(-255)
+ [-682]=>
+ int(-682)
+}
+Done
--- /dev/null
+--TEST--
+Test krsort() function : usage variations - sort array with diff. sub arrays
+--FILE--
+<?php
+/* Prototype : bool krsort ( array &$array [, int $sort_flags] )
+ * Description: Sort an array by key, maintaining key to data correlation
+ * Source code: ext/standard/array.c
+*/
+
+/*
+ * testing krsort() by providing arrays contains sub arrays for $array argument
+ * with flowing flag values
+ * 1.flag value as defualt
+ * 2.SORT_REGULAR - compare items normally
+*/
+
+echo "*** Testing krsort() : usage variations ***\n";
+
+// array with diff sub arrays to be sorted
+$various_arrays = array (
+ // null array
+ 1 => array(),
+
+ // array contains null sub array
+ 2 => array( 1 => array() ),
+
+ // array of arrays along with some values
+ 3 => array(4 => 44, 1 => 11, 3 => array(64,61) ),
+
+ // array contains sub arrays
+ 4 => array ( 3 => array(33,-5,6), 1 => array(11),
+ 2 => array(22,-55), 0 => array() )
+);
+
+
+$count = 1;
+echo "\n-- Testing krsort() by supplying various arrays containing sub arrays --\n";
+
+// loop through to test krsort() with different arrays
+foreach ($various_arrays as $array) {
+
+ echo "\n-- Iteration $count --\n";
+ echo "- With defualt sort flag -\n";
+ $temp_array = $array;
+ var_dump( krsort($temp_array) );
+ var_dump($temp_array);
+
+ echo "- Sort flag = SORT_REGULAR -\n";
+ $temp_array = $array;
+ var_dump( krsort($temp_array, SORT_REGULAR) );
+ var_dump($temp_array);
+ $count++;
+}
+
+echo "Done\n";
+?>
+--EXPECTF--
+*** Testing krsort() : usage variations ***
+
+-- Testing krsort() by supplying various arrays containing sub arrays --
+
+-- Iteration 1 --
+- With defualt sort flag -
+bool(true)
+array(0) {
+}
+- Sort flag = SORT_REGULAR -
+bool(true)
+array(0) {
+}
+
+-- Iteration 2 --
+- With defualt sort flag -
+bool(true)
+array(1) {
+ [1]=>
+ array(0) {
+ }
+}
+- Sort flag = SORT_REGULAR -
+bool(true)
+array(1) {
+ [1]=>
+ array(0) {
+ }
+}
+
+-- Iteration 3 --
+- With defualt sort flag -
+bool(true)
+array(3) {
+ [4]=>
+ int(44)
+ [3]=>
+ array(2) {
+ [0]=>
+ int(64)
+ [1]=>
+ int(61)
+ }
+ [1]=>
+ int(11)
+}
+- Sort flag = SORT_REGULAR -
+bool(true)
+array(3) {
+ [4]=>
+ int(44)
+ [3]=>
+ array(2) {
+ [0]=>
+ int(64)
+ [1]=>
+ int(61)
+ }
+ [1]=>
+ int(11)
+}
+
+-- Iteration 4 --
+- With defualt sort flag -
+bool(true)
+array(4) {
+ [3]=>
+ array(3) {
+ [0]=>
+ int(33)
+ [1]=>
+ int(-5)
+ [2]=>
+ int(6)
+ }
+ [2]=>
+ array(2) {
+ [0]=>
+ int(22)
+ [1]=>
+ int(-55)
+ }
+ [1]=>
+ array(1) {
+ [0]=>
+ int(11)
+ }
+ [0]=>
+ array(0) {
+ }
+}
+- Sort flag = SORT_REGULAR -
+bool(true)
+array(4) {
+ [3]=>
+ array(3) {
+ [0]=>
+ int(33)
+ [1]=>
+ int(-5)
+ [2]=>
+ int(6)
+ }
+ [2]=>
+ array(2) {
+ [0]=>
+ int(22)
+ [1]=>
+ int(-55)
+ }
+ [1]=>
+ array(1) {
+ [0]=>
+ int(11)
+ }
+ [0]=>
+ array(0) {
+ }
+}
+Done
--- /dev/null
+--TEST--
+Test krsort() function : usage variations - sort array with/without key values
+--FILE--
+<?php
+/* Prototype : bool krsort ( array &$array [, int $sort_flags] )
+ * Description: Sort an array by key in reverse order, maintaining key to data correlation.
+ * Source code: ext/standard/array.c
+*/
+
+/*
+ * Testing krsort() by providing arrays with/without key values for $array argument
+ * with following flag values:
+ * 1.flag value as defualt
+ * 2.SORT_REGULAR - compare items normally
+ */
+
+echo "*** Testing krsort() : usage variations ***\n";
+
+// list of arrays with/without key values
+$various_arrays = array (
+ array(5 => 55, 66, 22, 33, 11),
+ array ("a" => "orange", "banana", "c" => "apple"),
+ array(1, 2, 3, 4, 5, 6),
+ array("first", 5 => "second", 1 => "third"),
+ array(1, 1, 8 => 1, 4 => 1, 19, 3 => 13),
+ array('bar' => 'baz', "foo" => 1),
+ array('a' => 1,'b' => array('e' => 2,'f' => 3),'c' => array('g' => 4),'d' => 5),
+);
+
+$count = 1;
+echo "\n-- Testing krsort() by supplying various arrays with/without key values --\n";
+
+// loop through to test krsort() with different arrays,
+foreach ($various_arrays as $array) {
+ echo "\n-- Iteration $count --\n";
+
+ echo "- With defualt sort flag -\n";
+ $temp_array = $array;
+ var_dump( krsort($temp_array) );
+ var_dump($temp_array);
+
+ echo "- Sort flag = SORT_REGULAR -\n";
+ $temp_array = $array;
+ var_dump( krsort($temp_array, SORT_REGULAR) );
+ var_dump($temp_array);
+ $count++;
+}
+
+echo "Done\n";
+?>
+--EXPECTF--
+*** Testing krsort() : usage variations ***
+
+-- Testing krsort() by supplying various arrays with/without key values --
+
+-- Iteration 1 --
+- With defualt sort flag -
+bool(true)
+array(5) {
+ [9]=>
+ int(11)
+ [8]=>
+ int(33)
+ [7]=>
+ int(22)
+ [6]=>
+ int(66)
+ [5]=>
+ int(55)
+}
+- Sort flag = SORT_REGULAR -
+bool(true)
+array(5) {
+ [9]=>
+ int(11)
+ [8]=>
+ int(33)
+ [7]=>
+ int(22)
+ [6]=>
+ int(66)
+ [5]=>
+ int(55)
+}
+
+-- Iteration 2 --
+- With defualt sort flag -
+bool(true)
+array(3) {
+ ["c"]=>
+ string(5) "apple"
+ [0]=>
+ string(6) "banana"
+ ["a"]=>
+ string(6) "orange"
+}
+- Sort flag = SORT_REGULAR -
+bool(true)
+array(3) {
+ ["c"]=>
+ string(5) "apple"
+ [0]=>
+ string(6) "banana"
+ ["a"]=>
+ string(6) "orange"
+}
+
+-- Iteration 3 --
+- With defualt sort flag -
+bool(true)
+array(6) {
+ [5]=>
+ int(6)
+ [4]=>
+ int(5)
+ [3]=>
+ int(4)
+ [2]=>
+ int(3)
+ [1]=>
+ int(2)
+ [0]=>
+ int(1)
+}
+- Sort flag = SORT_REGULAR -
+bool(true)
+array(6) {
+ [5]=>
+ int(6)
+ [4]=>
+ int(5)
+ [3]=>
+ int(4)
+ [2]=>
+ int(3)
+ [1]=>
+ int(2)
+ [0]=>
+ int(1)
+}
+
+-- Iteration 4 --
+- With defualt sort flag -
+bool(true)
+array(3) {
+ [5]=>
+ string(6) "second"
+ [1]=>
+ string(5) "third"
+ [0]=>
+ string(5) "first"
+}
+- Sort flag = SORT_REGULAR -
+bool(true)
+array(3) {
+ [5]=>
+ string(6) "second"
+ [1]=>
+ string(5) "third"
+ [0]=>
+ string(5) "first"
+}
+
+-- Iteration 5 --
+- With defualt sort flag -
+bool(true)
+array(6) {
+ [9]=>
+ int(19)
+ [8]=>
+ int(1)
+ [4]=>
+ int(1)
+ [3]=>
+ int(13)
+ [1]=>
+ int(1)
+ [0]=>
+ int(1)
+}
+- Sort flag = SORT_REGULAR -
+bool(true)
+array(6) {
+ [9]=>
+ int(19)
+ [8]=>
+ int(1)
+ [4]=>
+ int(1)
+ [3]=>
+ int(13)
+ [1]=>
+ int(1)
+ [0]=>
+ int(1)
+}
+
+-- Iteration 6 --
+- With defualt sort flag -
+bool(true)
+array(2) {
+ ["foo"]=>
+ int(1)
+ ["bar"]=>
+ string(3) "baz"
+}
+- Sort flag = SORT_REGULAR -
+bool(true)
+array(2) {
+ ["foo"]=>
+ int(1)
+ ["bar"]=>
+ string(3) "baz"
+}
+
+-- Iteration 7 --
+- With defualt sort flag -
+bool(true)
+array(4) {
+ ["d"]=>
+ int(5)
+ ["c"]=>
+ array(1) {
+ ["g"]=>
+ int(4)
+ }
+ ["b"]=>
+ array(2) {
+ ["e"]=>
+ int(2)
+ ["f"]=>
+ int(3)
+ }
+ ["a"]=>
+ int(1)
+}
+- Sort flag = SORT_REGULAR -
+bool(true)
+array(4) {
+ ["d"]=>
+ int(5)
+ ["c"]=>
+ array(1) {
+ ["g"]=>
+ int(4)
+ }
+ ["b"]=>
+ array(2) {
+ ["e"]=>
+ int(2)
+ ["f"]=>
+ int(3)
+ }
+ ["a"]=>
+ int(1)
+}
+Done