summaryrefslogtreecommitdiff
path: root/ext/standard/tests/array/ksort_variation9.phpt
diff options
context:
space:
mode:
Diffstat (limited to 'ext/standard/tests/array/ksort_variation9.phpt')
-rw-r--r--ext/standard/tests/array/ksort_variation9.phpt256
1 files changed, 256 insertions, 0 deletions
diff --git a/ext/standard/tests/array/ksort_variation9.phpt b/ext/standard/tests/array/ksort_variation9.phpt
new file mode 100644
index 000000000..ed406e20b
--- /dev/null
+++ b/ext/standard/tests/array/ksort_variation9.phpt
@@ -0,0 +1,256 @@
+--TEST--
+Test ksort() function : usage variations - sorting arrays with/without keys
+--FILE--
+<?php
+/* Prototype : bool ksort ( array &$array [, int $sort_flags] )
+ * Description: Sort an array by key, maintaining key to data correlation.
+ * Source code: ext/standard/array.c
+*/
+
+/*
+ * Testing ksort() 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 ksort() : 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 ksort() by supplying various arrays with/without key values --\n";
+
+// loop through to test ksort() with different arrays,
+foreach ($various_arrays as $array) {
+ echo "\n-- Iteration $count --\n";
+
+ echo "- With defualt sort flag -\n";
+ $temp_array = $array;
+ var_dump( ksort($temp_array) );
+ var_dump($temp_array);
+
+ echo "- Sort flag = SORT_REGULAR -\n";
+ $temp_array = $array;
+ var_dump( ksort($temp_array, SORT_REGULAR) );
+ var_dump($temp_array);
+ $count++;
+}
+
+echo "Done\n";
+?>
+--EXPECTF--
+*** Testing ksort() : usage variations ***
+
+-- Testing ksort() by supplying various arrays with/without key values --
+
+-- Iteration 1 --
+- With defualt sort flag -
+bool(true)
+array(5) {
+ [5]=>
+ int(55)
+ [6]=>
+ int(66)
+ [7]=>
+ int(22)
+ [8]=>
+ int(33)
+ [9]=>
+ int(11)
+}
+- Sort flag = SORT_REGULAR -
+bool(true)
+array(5) {
+ [5]=>
+ int(55)
+ [6]=>
+ int(66)
+ [7]=>
+ int(22)
+ [8]=>
+ int(33)
+ [9]=>
+ int(11)
+}
+
+-- 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) {
+ [0]=>
+ int(1)
+ [1]=>
+ int(2)
+ [2]=>
+ int(3)
+ [3]=>
+ int(4)
+ [4]=>
+ int(5)
+ [5]=>
+ int(6)
+}
+- Sort flag = SORT_REGULAR -
+bool(true)
+array(6) {
+ [0]=>
+ int(1)
+ [1]=>
+ int(2)
+ [2]=>
+ int(3)
+ [3]=>
+ int(4)
+ [4]=>
+ int(5)
+ [5]=>
+ int(6)
+}
+
+-- Iteration 4 --
+- With defualt sort flag -
+bool(true)
+array(3) {
+ [0]=>
+ string(5) "first"
+ [1]=>
+ string(5) "third"
+ [5]=>
+ string(6) "second"
+}
+- Sort flag = SORT_REGULAR -
+bool(true)
+array(3) {
+ [0]=>
+ string(5) "first"
+ [1]=>
+ string(5) "third"
+ [5]=>
+ string(6) "second"
+}
+
+-- Iteration 5 --
+- With defualt sort flag -
+bool(true)
+array(6) {
+ [0]=>
+ int(1)
+ [1]=>
+ int(1)
+ [3]=>
+ int(13)
+ [4]=>
+ int(1)
+ [8]=>
+ int(1)
+ [9]=>
+ int(19)
+}
+- Sort flag = SORT_REGULAR -
+bool(true)
+array(6) {
+ [0]=>
+ int(1)
+ [1]=>
+ int(1)
+ [3]=>
+ int(13)
+ [4]=>
+ int(1)
+ [8]=>
+ int(1)
+ [9]=>
+ int(19)
+}
+
+-- Iteration 6 --
+- With defualt sort flag -
+bool(true)
+array(2) {
+ ["bar"]=>
+ string(3) "baz"
+ ["foo"]=>
+ int(1)
+}
+- Sort flag = SORT_REGULAR -
+bool(true)
+array(2) {
+ ["bar"]=>
+ string(3) "baz"
+ ["foo"]=>
+ int(1)
+}
+
+-- Iteration 7 --
+- With defualt sort flag -
+bool(true)
+array(4) {
+ ["a"]=>
+ int(1)
+ ["b"]=>
+ array(2) {
+ ["e"]=>
+ int(2)
+ ["f"]=>
+ int(3)
+ }
+ ["c"]=>
+ array(1) {
+ ["g"]=>
+ int(4)
+ }
+ ["d"]=>
+ int(5)
+}
+- Sort flag = SORT_REGULAR -
+bool(true)
+array(4) {
+ ["a"]=>
+ int(1)
+ ["b"]=>
+ array(2) {
+ ["e"]=>
+ int(2)
+ ["f"]=>
+ int(3)
+ }
+ ["c"]=>
+ array(1) {
+ ["g"]=>
+ int(4)
+ }
+ ["d"]=>
+ int(5)
+}
+Done