]> granicus.if.org Git - php/commitdiff
add support for SORT_NATURAL and SORT_FLAG_CASE in array sort functions
authorArpad Ray <arpad@php.net>
Mon, 29 Aug 2011 20:23:34 +0000 (20:23 +0000)
committerArpad Ray <arpad@php.net>
Mon, 29 Aug 2011 20:23:34 +0000 (20:23 +0000)
35 files changed:
NEWS
ext/standard/array.c
ext/standard/php_array.h
ext/standard/php_string.h
ext/standard/string.c
ext/standard/tests/array/array_multisort_basic1.phpt
ext/standard/tests/array/array_multisort_basic2.phpt
ext/standard/tests/array/array_multisort_case.phpt [new file with mode: 0644]
ext/standard/tests/array/array_multisort_error.phpt
ext/standard/tests/array/array_multisort_incase.phpt [new file with mode: 0644]
ext/standard/tests/array/array_multisort_natural.phpt [new file with mode: 0644]
ext/standard/tests/array/array_multisort_natural_case.phpt [new file with mode: 0644]
ext/standard/tests/array/array_multisort_natural_incase.phpt [new file with mode: 0644]
ext/standard/tests/array/array_multisort_variation1.phpt
ext/standard/tests/array/array_multisort_variation10.phpt
ext/standard/tests/array/array_multisort_variation11.phpt
ext/standard/tests/array/array_multisort_variation2.phpt
ext/standard/tests/array/array_multisort_variation3.phpt
ext/standard/tests/array/array_multisort_variation4.phpt
ext/standard/tests/array/array_multisort_variation5.phpt
ext/standard/tests/array/array_multisort_variation6.phpt
ext/standard/tests/array/array_multisort_variation7.phpt
ext/standard/tests/array/array_multisort_variation8.phpt
ext/standard/tests/array/array_multisort_variation9.phpt
ext/standard/tests/array/arsort_basic.phpt
ext/standard/tests/array/arsort_variation2.phpt
ext/standard/tests/array/asort_basic.phpt
ext/standard/tests/array/asort_variation2.phpt
ext/standard/tests/array/krsort_basic.phpt
ext/standard/tests/array/krsort_variation2.phpt
ext/standard/tests/array/ksort_basic.phpt
ext/standard/tests/array/ksort_variation2.phpt
ext/standard/tests/array/rsort_basic.phpt
ext/standard/tests/array/sort_basic.phpt
ext/standard/tests/array/sort_variation2.phpt

diff --git a/NEWS b/NEWS
index 3d38435749f11cdbd02cb66459328e529a0cdf8f..0fabddb4363f53e1635b11e089b31a33d423bccd 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -10,6 +10,8 @@ PHP                                                                        NEWS
     is small enough. (Derick)
   . Fixed bug #52461 (Incomplete doctype and missing xmlns). 
     (virsacer at web dot de, Pierre)
+  . Added support for SORT_NATURAL and SORT_FLAG_CASE in array sort functions:
+    sort, rsort, ksort, krsort, asort, arsort and array_multisort. Req #55158 (arpad)
 
 - Improved mbstring extension:
   . Added Shift_JIS/UTF-8 Emoji (pictograms) support. (Rui)
index ed967e339580c20c045d4cc10574e0f1fe45c448..d189c7faefefb9ea2037937410ecb4f48f78084d 100644 (file)
@@ -118,6 +118,8 @@ PHP_MINIT_FUNCTION(array) /* {{{ */
        REGISTER_LONG_CONSTANT("SORT_NUMERIC", PHP_SORT_NUMERIC, CONST_CS | CONST_PERSISTENT);
        REGISTER_LONG_CONSTANT("SORT_STRING", PHP_SORT_STRING, CONST_CS | CONST_PERSISTENT);
        REGISTER_LONG_CONSTANT("SORT_LOCALE_STRING", PHP_SORT_LOCALE_STRING, CONST_CS | CONST_PERSISTENT);
+       REGISTER_LONG_CONSTANT("SORT_NATURAL", PHP_SORT_NATURAL, CONST_CS | CONST_PERSISTENT);
+       REGISTER_LONG_CONSTANT("SORT_FLAG_CASE", PHP_SORT_FLAG_CASE, CONST_CS | CONST_PERSISTENT);
 
        REGISTER_LONG_CONSTANT("CASE_LOWER", CASE_LOWER, CONST_CS | CONST_PERSISTENT);
        REGISTER_LONG_CONSTANT("CASE_UPPER", CASE_UPPER, CONST_CS | CONST_PERSISTENT);
@@ -141,13 +143,17 @@ PHP_MSHUTDOWN_FUNCTION(array) /* {{{ */
 
 static void php_set_compare_func(int sort_type TSRMLS_DC) /* {{{ */
 {
-       switch (sort_type) {
+       switch (sort_type & ~PHP_SORT_FLAG_CASE) {
                case PHP_SORT_NUMERIC:
                        ARRAYG(compare_func) = numeric_compare_function;
                        break;
 
                case PHP_SORT_STRING:
-                       ARRAYG(compare_func) = string_compare_function;
+                       ARRAYG(compare_func) = sort_type & PHP_SORT_FLAG_CASE ? string_case_compare_function : string_compare_function;
+                       break;
+
+               case PHP_SORT_NATURAL:
+                       ARRAYG(compare_func) = sort_type & PHP_SORT_FLAG_CASE ? string_natural_case_compare_function : string_natural_compare_function;
                        break;
 
 #if HAVE_STRCOLL
@@ -3762,7 +3768,7 @@ PHPAPI int php_multisort_compare(const void *a, const void *b TSRMLS_DC) /* {{{
        efree(args);                                                    \
        RETURN_FALSE;
 
-/* {{{ proto bool array_multisort(array ar1 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING]] [, array ar2 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING]], ...])
+/* {{{ proto 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]], ...])
    Sort multiple arrays at once similar to how ORDER BY clause works in SQL */
 PHP_FUNCTION(array_multisort)
 {
@@ -3812,7 +3818,7 @@ PHP_FUNCTION(array_multisort)
                                parse_state[k] = 1;
                        }
                } else if (Z_TYPE_PP(args[i]) == IS_LONG) {
-                       switch (Z_LVAL_PP(args[i])) {
+                       switch (Z_LVAL_PP(args[i]) & ~PHP_SORT_FLAG_CASE) {
                                case PHP_SORT_ASC:
                                case PHP_SORT_DESC:
                                        /* flag allowed here */
@@ -3829,6 +3835,7 @@ PHP_FUNCTION(array_multisort)
                                case PHP_SORT_REGULAR:
                                case PHP_SORT_NUMERIC:
                                case PHP_SORT_STRING:
+                               case PHP_SORT_NATURAL:
 #if HAVE_STRCOLL
                                case PHP_SORT_LOCALE_STRING:
 #endif
index 07a38cfd916b2bbb19a66494b334cc4b698e41fc..779536e006d68a5afa04fda07280548f877f0aa7 100644 (file)
@@ -113,6 +113,8 @@ PHPAPI int php_multisort_compare(const void *a, const void *b TSRMLS_DC);
 #define PHP_SORT_DESC               3
 #define PHP_SORT_ASC                4
 #define PHP_SORT_LOCALE_STRING      5
+#define PHP_SORT_NATURAL            6
+#define PHP_SORT_FLAG_CASE          8
 
 ZEND_BEGIN_MODULE_GLOBALS(array) 
        int *multisort_flags[2];
index c6d916dbcc182ef8732b63c293e81d1fb87a8c31..8284204c8902c6de7df985cf82a17b522ec58832 100644 (file)
@@ -143,6 +143,10 @@ PHPAPI void php_explode(zval *delim, zval *str, zval *return_value, long limit);
 PHPAPI size_t php_strspn(char *s1, char *s2, char *s1_end, char *s2_end); 
 PHPAPI size_t php_strcspn(char *s1, char *s2, char *s1_end, char *s2_end); 
 
+PHPAPI int string_natural_compare_function_ex(zval *result, zval *op1, zval *op2, zend_bool case_insensitive TSRMLS_DC);
+PHPAPI int string_natural_compare_function(zval *result, zval *op1, zval *op2 TSRMLS_DC);
+PHPAPI int string_natural_case_compare_function(zval *result, zval *op1, zval *op2 TSRMLS_DC);
+
 #ifndef HAVE_STRERROR
 PHPAPI char *php_strerror(int errnum);
 #define strerror php_strerror
index 1717b3b711593d298f7dc17b7e023c36bae42339..62599d40196ce9b0c11ea8ebd2bcf8dca5d38d71 100644 (file)
@@ -4734,6 +4734,49 @@ static void php_strnatcmp(INTERNAL_FUNCTION_PARAMETERS, int fold_case)
 }
 /* }}} */
 
+PHPAPI int string_natural_compare_function_ex(zval *result, zval *op1, zval *op2, zend_bool case_insensitive TSRMLS_DC) /* {{{ */
+{
+       zval op1_copy, op2_copy;
+       int use_copy1 = 0, use_copy2 = 0, sort_result;
+
+       if (Z_TYPE_P(op1) != IS_STRING) {
+               zend_make_printable_zval(op1, &op1_copy, &use_copy1);
+       }
+       if (Z_TYPE_P(op2) != IS_STRING) {
+               zend_make_printable_zval(op2, &op2_copy, &use_copy2);
+       }
+
+       if (use_copy1) {
+               op1 = &op1_copy;
+       }
+       if (use_copy2) {
+               op2 = &op2_copy;
+       }
+
+       ZVAL_LONG(result, strnatcmp_ex(Z_STRVAL_P(op1), Z_STRLEN_P(op1), Z_STRVAL_P(op2), Z_STRLEN_P(op2), case_insensitive));
+
+       if (use_copy1) {
+               zval_dtor(op1);
+       }
+       if (use_copy2) {
+               zval_dtor(op2);
+       }
+       return SUCCESS;
+}
+/* }}} */
+
+PHPAPI int string_natural_case_compare_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{{ */
+{
+       return string_natural_compare_function_ex(result, op1, op2, 1 TSRMLS_CC);
+}
+/* }}} */
+
+PHPAPI int string_natural_compare_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{{ */
+{
+       return string_natural_compare_function_ex(result, op1, op2, 0 TSRMLS_CC);
+}
+/* }}} */
+
 /* {{{ proto int strnatcmp(string s1, string s2)
    Returns the result of string comparison using 'natural' algorithm */
 PHP_FUNCTION(strnatcmp)
index af5f8df4f32ac46419202b46bd6905b63ed0ffc9..ab7db944635f7188e8f336bc7571b638338bb870 100644 (file)
@@ -2,7 +2,7 @@
 Test array_multisort() function : basic functionality 
 --FILE--
 <?php
-/* Prototype  : bool array_multisort(array ar1 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING]] [, array ar2 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING]], ...])
+/* 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]], ...])
  * Description: Sort multiple arrays at once similar to how ORDER BY clause works in SQL 
  * Source code: ext/standard/array.c
  * Alias to functions: 
index d2c7ac20b79036c9e9fe724ac3f2c09e76521013..4a46072e65bb0ea6d33b90208730cac757318133 100644 (file)
@@ -2,7 +2,7 @@
 Test array_multisort() function : basic functionality 
 --FILE--
 <?php
-/* Prototype  : bool array_multisort(array ar1 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING]] [, array ar2 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING]], ...])
+/* 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]], ...])
  * Description: Sort multiple arrays at once similar to how ORDER BY clause works in SQL 
  * Source code: ext/standard/array.c
  * Alias to functions: 
diff --git a/ext/standard/tests/array/array_multisort_case.phpt b/ext/standard/tests/array/array_multisort_case.phpt
new file mode 100644 (file)
index 0000000..6be42ed
--- /dev/null
@@ -0,0 +1,73 @@
+--TEST--
+Test array_multisort() function : case-sensitive
+--FILE--
+<?php
+/* 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], ...])
+ * Description: Sort multiple arrays at once similar to how ORDER BY clause works in SQL 
+ * Source code: ext/standard/array.c
+ * Alias to functions: 
+ */
+
+echo "*** Testing array_multisort() : case-sensitive\n";
+
+$a = array(
+       'Second',
+       'First.1',
+       'First.2',
+       'First.3',
+       'Twentieth',
+       'Tenth',
+       'Third',
+);
+
+$b = array(
+       '2 a',
+       '1 bb 1',
+       '1 bB 2',
+       '1 BB 3',
+       '20 c',
+       '10 d',
+       '3 e',
+);
+
+array_multisort($b, SORT_STRING, $a);
+
+var_dump($a, $b);
+
+?>
+===DONE===
+--EXPECTF--
+*** Testing array_multisort() : case-sensitive
+array(7) {
+  [0]=>
+  string(7) "First.3"
+  [1]=>
+  string(7) "First.2"
+  [2]=>
+  string(7) "First.1"
+  [3]=>
+  string(5) "Tenth"
+  [4]=>
+  string(6) "Second"
+  [5]=>
+  string(9) "Twentieth"
+  [6]=>
+  string(5) "Third"
+}
+array(7) {
+  [0]=>
+  string(6) "1 BB 3"
+  [1]=>
+  string(6) "1 bB 2"
+  [2]=>
+  string(6) "1 bb 1"
+  [3]=>
+  string(4) "10 d"
+  [4]=>
+  string(3) "2 a"
+  [5]=>
+  string(4) "20 c"
+  [6]=>
+  string(3) "3 e"
+}
+===DONE===
index 7cd95ec1698aa1f6c54ac8d447c34f73eb073fc2..5956630f845e87506c51030b441e5991813cb9b7 100644 (file)
@@ -2,7 +2,7 @@
 Test array_multisort() function : error conditions 
 --FILE--
 <?php
-/* Prototype  : bool array_multisort(array ar1 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING]] [, array ar2 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING]], ...])
+/* 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]], ...])
  * Description: Sort multiple arrays at once similar to how ORDER BY clause works in SQL 
  * Source code: ext/standard/array.c
  * Alias to functions: 
diff --git a/ext/standard/tests/array/array_multisort_incase.phpt b/ext/standard/tests/array/array_multisort_incase.phpt
new file mode 100644 (file)
index 0000000..951cce4
--- /dev/null
@@ -0,0 +1,73 @@
+--TEST--
+Test array_multisort() function : case-insensitive
+--FILE--
+<?php
+/* 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], ...])
+ * Description: Sort multiple arrays at once similar to how ORDER BY clause works in SQL 
+ * Source code: ext/standard/array.c
+ * Alias to functions: 
+ */
+
+echo "*** Testing array_multisort() : case-insensitive\n";
+
+$a = array(
+       'Second',
+       'First.1',
+       'First.2',
+       'First.3',
+       'Twentieth',
+       'Tenth',
+       'Third',
+);
+
+$b = array(
+       '2 a',
+       '1 bb 1',
+       '1 bB 2',
+       '1 BB 3',
+       '20 c',
+       '10 d',
+       '3 e',
+);
+
+array_multisort($b, SORT_STRING | SORT_FLAG_CASE, $a);
+
+var_dump($a, $b);
+
+?>
+===DONE===
+--EXPECTF--
+*** Testing array_multisort() : case-insensitive
+array(7) {
+  [0]=>
+  string(7) "First.1"
+  [1]=>
+  string(7) "First.2"
+  [2]=>
+  string(7) "First.3"
+  [3]=>
+  string(5) "Tenth"
+  [4]=>
+  string(6) "Second"
+  [5]=>
+  string(9) "Twentieth"
+  [6]=>
+  string(5) "Third"
+}
+array(7) {
+  [0]=>
+  string(6) "1 bb 1"
+  [1]=>
+  string(6) "1 bB 2"
+  [2]=>
+  string(6) "1 BB 3"
+  [3]=>
+  string(4) "10 d"
+  [4]=>
+  string(3) "2 a"
+  [5]=>
+  string(4) "20 c"
+  [6]=>
+  string(3) "3 e"
+}
+===DONE===
diff --git a/ext/standard/tests/array/array_multisort_natural.phpt b/ext/standard/tests/array/array_multisort_natural.phpt
new file mode 100644 (file)
index 0000000..e791088
--- /dev/null
@@ -0,0 +1,61 @@
+--TEST--
+Test array_multisort() function : natural sorting
+--FILE--
+<?php
+/* 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], ...])
+ * Description: Sort multiple arrays at once similar to how ORDER BY clause works in SQL 
+ * Source code: ext/standard/array.c
+ * Alias to functions: 
+ */
+
+echo "*** Testing array_multisort() : natural sorting\n";
+
+$a = array(
+       'Second',
+       'First',
+       'Twentieth',
+       'Tenth',
+       'Third',
+);
+
+$b = array(
+       '2 a',
+       '1 b',
+       '20 c',
+       '10 d',
+       '3 e',
+);
+
+array_multisort($b, SORT_NATURAL, $a);
+
+var_dump($a, $b);
+
+?>
+===DONE===
+--EXPECTF--
+*** Testing array_multisort() : natural sorting
+array(5) {
+  [0]=>
+  string(5) "First"
+  [1]=>
+  string(6) "Second"
+  [2]=>
+  string(5) "Third"
+  [3]=>
+  string(5) "Tenth"
+  [4]=>
+  string(9) "Twentieth"
+}
+array(5) {
+  [0]=>
+  string(3) "1 b"
+  [1]=>
+  string(3) "2 a"
+  [2]=>
+  string(3) "3 e"
+  [3]=>
+  string(4) "10 d"
+  [4]=>
+  string(4) "20 c"
+}
+===DONE===
diff --git a/ext/standard/tests/array/array_multisort_natural_case.phpt b/ext/standard/tests/array/array_multisort_natural_case.phpt
new file mode 100644 (file)
index 0000000..d59e493
--- /dev/null
@@ -0,0 +1,73 @@
+--TEST--
+Test array_multisort() function : natural sorting case-sensitive
+--FILE--
+<?php
+/* 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], ...])
+ * Description: Sort multiple arrays at once similar to how ORDER BY clause works in SQL 
+ * Source code: ext/standard/array.c
+ * Alias to functions: 
+ */
+
+echo "*** Testing array_multisort() : natural sorting case-sensitive\n";
+
+$a = array(
+       'Second',
+       'First.1',
+       'First.2',
+       'First.3',
+       'Twentieth',
+       'Tenth',
+       'Third',
+);
+
+$b = array(
+       '2 a',
+       '1 bb 1',
+       '1 bB 2',
+       '1 BB 3',
+       '20 c',
+       '10 d',
+       '3 e',
+);
+
+array_multisort($b, SORT_NATURAL, $a);
+
+var_dump($a, $b);
+
+?>
+===DONE===
+--EXPECTF--
+*** Testing array_multisort() : natural sorting case-sensitive
+array(7) {
+  [0]=>
+  string(7) "First.3"
+  [1]=>
+  string(7) "First.2"
+  [2]=>
+  string(7) "First.1"
+  [3]=>
+  string(6) "Second"
+  [4]=>
+  string(5) "Third"
+  [5]=>
+  string(5) "Tenth"
+  [6]=>
+  string(9) "Twentieth"
+}
+array(7) {
+  [0]=>
+  string(6) "1 BB 3"
+  [1]=>
+  string(6) "1 bB 2"
+  [2]=>
+  string(6) "1 bb 1"
+  [3]=>
+  string(3) "2 a"
+  [4]=>
+  string(3) "3 e"
+  [5]=>
+  string(4) "10 d"
+  [6]=>
+  string(4) "20 c"
+}
+===DONE===
diff --git a/ext/standard/tests/array/array_multisort_natural_incase.phpt b/ext/standard/tests/array/array_multisort_natural_incase.phpt
new file mode 100644 (file)
index 0000000..8751405
--- /dev/null
@@ -0,0 +1,73 @@
+--TEST--
+Test array_multisort() function : natural sorting case-insensitive
+--FILE--
+<?php
+/* 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], ...])
+ * Description: Sort multiple arrays at once similar to how ORDER BY clause works in SQL 
+ * Source code: ext/standard/array.c
+ * Alias to functions: 
+ */
+
+echo "*** Testing array_multisort() : natural sorting case-insensitive\n";
+
+$a = array(
+       'Second',
+       'First.1',
+       'First.2',
+       'First.3',
+       'Twentieth',
+       'Tenth',
+       'Third',
+);
+
+$b = array(
+       '2 a',
+       '1 bb 1',
+       '1 bB 2',
+       '1 BB 3',
+       '20 c',
+       '10 d',
+       '3 e',
+);
+
+array_multisort($b, SORT_NATURAL | SORT_FLAG_CASE, $a);
+
+var_dump($a, $b);
+
+?>
+===DONE===
+--EXPECTF--
+*** Testing array_multisort() : natural sorting case-insensitive
+array(7) {
+  [0]=>
+  string(7) "First.1"
+  [1]=>
+  string(7) "First.2"
+  [2]=>
+  string(7) "First.3"
+  [3]=>
+  string(6) "Second"
+  [4]=>
+  string(5) "Third"
+  [5]=>
+  string(5) "Tenth"
+  [6]=>
+  string(9) "Twentieth"
+}
+array(7) {
+  [0]=>
+  string(6) "1 bb 1"
+  [1]=>
+  string(6) "1 bB 2"
+  [2]=>
+  string(6) "1 BB 3"
+  [3]=>
+  string(3) "2 a"
+  [4]=>
+  string(3) "3 e"
+  [5]=>
+  string(4) "10 d"
+  [6]=>
+  string(4) "20 c"
+}
+===DONE===
index 084addef406f5c80a84b26374cd29374560a0134..93c265922e5842852fcca3b9385fe858a528cb88 100644 (file)
@@ -2,7 +2,7 @@
 Test array_multisort() function : usage variation 
 --FILE--
 <?php
-/* Prototype  : bool array_multisort(array ar1 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING]] [, array ar2 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING]], ...])
+/* 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]], ...])
  * Description: Sort multiple arrays at once similar to how ORDER BY clause works in SQL 
  * Source code: ext/standard/array.c
  * Alias to functions: 
index 4e9f4890ca6d7ada13a7bf6e29215376821e2d66..71c449427062045d062cf283b7d5ea357f3662aa 100644 (file)
@@ -2,7 +2,7 @@
 Test array_multisort() function : usage variation - testing with anonymous arrary arguments 
 --FILE--
 <?php
-/* Prototype  : bool array_multisort(array ar1 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING]] [, array ar2 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING]], ...])
+/* 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]], ...])
  * Description: Sort multiple arrays at once similar to how ORDER BY clause works in SQL 
  * Source code: ext/standard/array.c
  * Alias to functions: 
index 520dd3d51a27de5a9f44092d3d4bd1fe7b2d0a25..046b45f02049fac24678452e824369d23be8c5cd 100644 (file)
@@ -2,7 +2,7 @@
 Test array_multisort() function : usage variation - testing with empty array
 --FILE--
 <?php
-/* Prototype  : bool array_multisort(array ar1 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING]] [, array ar2 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING]], ...])
+/* 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]], ...])
  * Description: Sort multiple arrays at once similar to how ORDER BY clause works in SQL
  * Source code: ext/standard/array.c
  * Alias to functions:
index bad20188ed8644de7f1321162593f7025a02d84f..86210eeb492ef8ce9793bb1dbb296b666e204928 100644 (file)
@@ -2,7 +2,7 @@
 Test array_multisort() function : usage variation 
 --FILE--
 <?php
-/* Prototype  : bool array_multisort(array ar1 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING]] [, array ar2 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING]], ...])
+/* 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]], ...])
  * Description: Sort multiple arrays at once similar to how ORDER BY clause works in SQL 
  * Source code: ext/standard/array.c
  * Alias to functions: 
@@ -101,7 +101,7 @@ $inputs = array(
       'unset var' => @$unset_var,
 );
 
-// loop through each element of the array for SORT_REGULAR|SORT_NUMERIC|SORT_STRING]]
+// loop through each element of the array for SORT_REGULAR|SORT_NUMERIC|SORT_STRING|SORT_NATURAL|SORT_FLAG_CASE]]
 
 foreach($inputs as $key =>$value) {
       echo "\n--$key--\n";
index 534374c431618a202ef4fd551e1e9e9a63cec695..b2cdb05ece333492d410ad7d9a4c405414ba1aed 100644 (file)
@@ -2,7 +2,7 @@
 Test array_multisort() function : usage variation 
 --FILE--
 <?php
-/* Prototype  : bool array_multisort(array ar1 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING]] [, array ar2 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING]], ...])
+/* 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]], ...])
  * Description: Sort multiple arrays at once similar to how ORDER BY clause works in SQL 
  * Source code: ext/standard/array.c
  * Alias to functions: 
index ce2ae23564bbd16744a00c5d1d34b96b327ca712..5d11fb3ac06058ec11647a9c81f3d8b470aabf06 100644 (file)
@@ -2,7 +2,7 @@
 Test array_multisort() function : usage variation - testing with multiple array arguments 
 --FILE--
 <?php
-/* Prototype  : bool array_multisort(array ar1 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING]] [, array ar2 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING]], ...])
+/* 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]], ...])
  * Description: Sort multiple arrays at once similar to how ORDER BY clause works in SQL 
  * Source code: ext/standard/array.c
  * Alias to functions: 
index 87e60f22b1f6906c6337c13aeeab007fca72c5d1..76d7092c2109f9ac37168dcf48388a4e42814ad6 100644 (file)
@@ -2,7 +2,7 @@
 Test array_multisort() function : usage variation - testing with multiple array arguments 
 --FILE--
 <?php
-/* Prototype  : bool array_multisort(array ar1 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING]] [, array ar2 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING]], ...])
+/* 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]], ...])
  * Description: Sort multiple arrays at once similar to how ORDER BY clause works in SQL 
  * Source code: ext/standard/array.c
  * Alias to functions: 
index 9774d49badf8809abfbd51ec4884c124a5c71e00..4e2a62227df95d45b5f244050a8f86fcd84dcebe 100644 (file)
@@ -2,7 +2,7 @@
 Test array_multisort() function : usage variation - testing with multiple array arguments 
 --FILE--
 <?php
-/* Prototype  : bool array_multisort(array ar1 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING]] [, array ar2 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING]], ...])
+/* 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]], ...])
  * Description: Sort multiple arrays at once similar to how ORDER BY clause works in SQL 
  * Source code: ext/standard/array.c
  * Alias to functions: 
index c8ca24013a9ea4633d75941f19d4be4138652b7b..4e9feb512691b73b12626669297fbc5ec0780261 100644 (file)
@@ -2,7 +2,7 @@
 Test array_multisort() function : usage variation - test sort order of all types
 --FILE--
 <?php
-/* Prototype  : bool array_multisort(array ar1 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING]] [, array ar2 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING]], ...])
+/* 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]], ...])
  * Description: Sort multiple arrays at once similar to how ORDER BY clause works in SQL 
  * Source code: ext/standard/array.c
  * Alias to functions: 
index 60f7a97e32ecdd03ec00d4990fc584cff3e778a5..1995ee8d2bb79d9608d51187e017593601e7243a 100644 (file)
@@ -2,7 +2,7 @@
 Test array_multisort() function : usage variation - test sort order of all types
 --FILE--
 <?php
-/* Prototype  : bool array_multisort(array ar1 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING]] [, array ar2 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING]], ...])
+/* 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]], ...])
  * Description: Sort multiple arrays at once similar to how ORDER BY clause works in SQL 
  * Source code: ext/standard/array.c
  * Alias to functions: 
index 98ccd06ed01fa0fddf8a890dfe50410de0cfb9aa..b56357a4a38ec03089bf24ecb0d8c76f2841d16a 100644 (file)
@@ -2,7 +2,7 @@
 Test array_multisort() function : usage variation - test sort order of all types
 --FILE--
 <?php
-/* Prototype  : bool array_multisort(array ar1 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING]] [, array ar2 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING]], ...])
+/* 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]], ...])
  * Description: Sort multiple arrays at once similar to how ORDER BY clause works in SQL 
  * Source code: ext/standard/array.c
  * Alias to functions: 
index 481a590701284e5f44d027ae7391a7fa3f0f0d83..24799ab771a8f295fe185afe466bd10de24e9ba0 100644 (file)
@@ -20,7 +20,11 @@ Test arsort() function : basic functionality
 echo "*** Testing arsort() : basic functionality ***\n";
 
 // an array containing unsorted string values with indices  
-$unsorted_strings =   array( "l" => "lemon", "o" => "orange", "b" => "banana" ); 
+$unsorted_strings = array(
+       "l" => "lemon", "o" => "orange",
+       "O" => "Orange", "O1" => "Orange1", "o2" => "orange2", "O3" => "Orange3", "o20" => "orange20",
+       "b" => "banana",
+);
 // an array containing unsorted numeric values with indices 
 $unsorted_numerics =  array( 1 => 100, 2 => 33, 3 => 555, 4 => 22 );
 
@@ -49,6 +53,21 @@ $temp_array = $unsorted_strings;
 var_dump( arsort($temp_array, SORT_STRING) ); // expecting : bool(true)
 var_dump( $temp_array);
 
+echo "\n-- Testing arsort() by supplying string array (case insensitive), 'flag' = SORT_STRING|SORT_FLAG_CASE --\n";
+$temp_array = $unsorted_strings;
+var_dump( arsort($temp_array, SORT_STRING|SORT_FLAG_CASE) ); // expecting : bool(true)
+var_dump( $temp_array);
+
+echo "\n-- Testing arsort() by supplying string array (natural), 'flag' = SORT_NATURAL --\n";
+$temp_array = $unsorted_strings;
+var_dump( arsort($temp_array, SORT_NATURAL) ); // expecting : bool(true)
+var_dump( $temp_array);
+
+echo "\n-- Testing arsort() by supplying string array (natural, case insensitive), 'flag' = SORT_NATURAL|SORT_FLAG_CASE --\n";
+$temp_array = $unsorted_strings;
+var_dump( arsort($temp_array, SORT_NATURAL|SORT_FLAG_CASE) ); // expecting : bool(true)
+var_dump( $temp_array);
+
 echo "\n-- Testing arsort() by supplying numeric array, 'flag' = SORT_NUMERIC --\n";
 $temp_array = $unsorted_numerics;
 var_dump( arsort($temp_array, SORT_NUMERIC) ); // expecting : bool(true)
@@ -61,13 +80,23 @@ echo "Done\n";
 
 -- Testing arsort() by supplying string array, 'flag' value is default --
 bool(true)
-array(3) {
+array(8) {
+  ["o20"]=>
+  string(8) "orange20"
+  ["o2"]=>
+  string(7) "orange2"
   ["o"]=>
   string(6) "orange"
   ["l"]=>
   string(5) "lemon"
   ["b"]=>
   string(6) "banana"
+  ["O3"]=>
+  string(7) "Orange3"
+  ["O1"]=>
+  string(7) "Orange1"
+  ["O"]=>
+  string(6) "Orange"
 }
 
 -- Testing arsort() by supplying numeric array, 'flag' value is default --
@@ -85,13 +114,23 @@ array(4) {
 
 -- Testing arsort() by supplying string array, 'flag' = SORT_REGULAR --
 bool(true)
-array(3) {
+array(8) {
+  ["o20"]=>
+  string(8) "orange20"
+  ["o2"]=>
+  string(7) "orange2"
   ["o"]=>
   string(6) "orange"
   ["l"]=>
   string(5) "lemon"
   ["b"]=>
   string(6) "banana"
+  ["O3"]=>
+  string(7) "Orange3"
+  ["O1"]=>
+  string(7) "Orange1"
+  ["O"]=>
+  string(6) "Orange"
 }
 
 -- Testing arsort() by supplying numeric array, 'flag' = SORT_REGULAR --
@@ -109,9 +148,82 @@ array(4) {
 
 -- Testing arsort() by supplying string array, 'flag' = SORT_STRING --
 bool(true)
-array(3) {
+array(8) {
+  ["o20"]=>
+  string(8) "orange20"
+  ["o2"]=>
+  string(7) "orange2"
+  ["o"]=>
+  string(6) "orange"
+  ["l"]=>
+  string(5) "lemon"
+  ["b"]=>
+  string(6) "banana"
+  ["O3"]=>
+  string(7) "Orange3"
+  ["O1"]=>
+  string(7) "Orange1"
+  ["O"]=>
+  string(6) "Orange"
+}
+
+-- Testing arsort() by supplying string array (case insensitive), 'flag' = SORT_STRING|SORT_FLAG_CASE --
+bool(true)
+array(8) {
+  ["O3"]=>
+  string(7) "Orange3"
+  ["o20"]=>
+  string(8) "orange20"
+  ["o2"]=>
+  string(7) "orange2"
+  ["O1"]=>
+  string(7) "Orange1"
+  ["o"]=>
+  string(6) "orange"
+  ["O"]=>
+  string(6) "Orange"
+  ["l"]=>
+  string(5) "lemon"
+  ["b"]=>
+  string(6) "banana"
+}
+
+-- Testing arsort() by supplying string array (natural), 'flag' = SORT_NATURAL --
+bool(true)
+array(8) {
+  ["o20"]=>
+  string(8) "orange20"
+  ["o2"]=>
+  string(7) "orange2"
+  ["o"]=>
+  string(6) "orange"
+  ["l"]=>
+  string(5) "lemon"
+  ["b"]=>
+  string(6) "banana"
+  ["O3"]=>
+  string(7) "Orange3"
+  ["O1"]=>
+  string(7) "Orange1"
+  ["O"]=>
+  string(6) "Orange"
+}
+
+-- Testing arsort() by supplying string array (natural, case insensitive), 'flag' = SORT_NATURAL|SORT_FLAG_CASE --
+bool(true)
+array(8) {
+  ["o20"]=>
+  string(8) "orange20"
+  ["O3"]=>
+  string(7) "Orange3"
+  ["o2"]=>
+  string(7) "orange2"
+  ["O1"]=>
+  string(7) "Orange1"
   ["o"]=>
   string(6) "orange"
+  ["O"]=>
+  string(6) "Orange"
   ["l"]=>
   string(5) "lemon"
   ["b"]=>
index ab04b4409945b87394ae7016b9fbc9d51924b3df..b85653052f730a3da5a322c79f9365bb255e7fd1 100644 (file)
@@ -104,10 +104,10 @@ bool(true)
 array(3) {
   [3]=>
   int(45)
-  [1]=>
-  int(10)
   [2]=>
   int(2)
+  [1]=>
+  int(10)
 }
 -- Iteration 3 --
 bool(true)
@@ -305,4 +305,4 @@ array(3) {
   [3]=>
   int(45)
 }
-Done
\ No newline at end of file
+Done
index 13fa4f794e8e0da3e053ef66ba0e0c15817278b9..b80d31d37f0e14638150e3ec59c52e9d838f8e87 100644 (file)
@@ -20,7 +20,11 @@ Test asort() function : basic functionality
 echo "*** Testing asort() : basic functionality ***\n";
 
 // an array containing unsorted string values with indices  
-$unsorted_strings =   array( "l" => "lemon", "o" => "orange", "b" => "banana" ); 
+$unsorted_strings = array(
+       "l" => "lemon", "o" => "orange",
+       "O" => "Orange", "O1" => "Orange1", "o2" => "orange2", "O3" => "Orange3", "o20" => "orange20",
+       "b" => "banana",
+);
 // an array containing unsorted numeric values with indices 
 $unsorted_numerics =  array( 1 => 100, 2 => 33, 3 => 555, 4 => 22 );
 
@@ -49,6 +53,21 @@ $temp_array = $unsorted_strings;
 var_dump( asort($temp_array, SORT_STRING) ); // expecting : bool(true)
 var_dump( $temp_array);
 
+echo "\n-- Testing asort() by supplying string array (case insensitive), 'flag' = SORT_STRING|SORT_FLAG_CASE --\n";
+$temp_array = $unsorted_strings;
+var_dump( asort($temp_array, SORT_STRING|SORT_FLAG_CASE) ); // expecting : bool(true)
+var_dump( $temp_array);
+
+echo "\n-- Testing asort() by supplying string array (natural), 'flag' = SORT_NATURAL --\n";
+$temp_array = $unsorted_strings;
+var_dump( asort($temp_array, SORT_NATURAL) ); // expecting : bool(true)
+var_dump( $temp_array);
+
+echo "\n-- Testing asort() by supplying string array (natural, case insensitive), 'flag' = SORT_NATURAL|SORT_FLAG_CASE --\n";
+$temp_array = $unsorted_strings;
+var_dump( asort($temp_array, SORT_NATURAL|SORT_FLAG_CASE) ); // expecting : bool(true)
+var_dump( $temp_array);
+
 echo "\n-- Testing asort() by supplying numeric array, 'flag' = SORT_NUMERIC --\n";
 $temp_array = $unsorted_numerics;
 var_dump( asort($temp_array, SORT_NUMERIC) ); // expecting : bool(true)
@@ -61,13 +80,23 @@ echo "Done\n";
 
 -- Testing asort() by supplying string array, 'flag' value is default --
 bool(true)
-array(3) {
+array(8) {
+  ["O"]=>
+  string(6) "Orange"
+  ["O1"]=>
+  string(7) "Orange1"
+  ["O3"]=>
+  string(7) "Orange3"
   ["b"]=>
   string(6) "banana"
   ["l"]=>
   string(5) "lemon"
   ["o"]=>
   string(6) "orange"
+  ["o2"]=>
+  string(7) "orange2"
+  ["o20"]=>
+  string(8) "orange20"
 }
 
 -- Testing asort() by supplying numeric array, 'flag' value is default --
@@ -85,13 +114,23 @@ array(4) {
 
 -- Testing asort() by supplying string array, 'flag' = SORT_REGULAR --
 bool(true)
-array(3) {
+array(8) {
+  ["O"]=>
+  string(6) "Orange"
+  ["O1"]=>
+  string(7) "Orange1"
+  ["O3"]=>
+  string(7) "Orange3"
   ["b"]=>
   string(6) "banana"
   ["l"]=>
   string(5) "lemon"
   ["o"]=>
   string(6) "orange"
+  ["o2"]=>
+  string(7) "orange2"
+  ["o20"]=>
+  string(8) "orange20"
 }
 
 -- Testing asort() by supplying numeric array, 'flag' = SORT_REGULAR --
@@ -109,13 +148,86 @@ array(4) {
 
 -- Testing asort() by supplying string array, 'flag' = SORT_STRING --
 bool(true)
-array(3) {
+array(8) {
+  ["O"]=>
+  string(6) "Orange"
+  ["O1"]=>
+  string(7) "Orange1"
+  ["O3"]=>
+  string(7) "Orange3"
+  ["b"]=>
+  string(6) "banana"
+  ["l"]=>
+  string(5) "lemon"
+  ["o"]=>
+  string(6) "orange"
+  ["o2"]=>
+  string(7) "orange2"
+  ["o20"]=>
+  string(8) "orange20"
+}
+
+-- Testing asort() by supplying string array (case insensitive), 'flag' = SORT_STRING|SORT_FLAG_CASE --
+bool(true)
+array(8) {
+  ["b"]=>
+  string(6) "banana"
+  ["l"]=>
+  string(5) "lemon"
+  ["o"]=>
+  string(6) "orange"
+  ["O"]=>
+  string(6) "Orange"
+  ["O1"]=>
+  string(7) "Orange1"
+  ["o2"]=>
+  string(7) "orange2"
+  ["o20"]=>
+  string(8) "orange20"
+  ["O3"]=>
+  string(7) "Orange3"
+}
+
+-- Testing asort() by supplying string array (natural), 'flag' = SORT_NATURAL --
+bool(true)
+array(8) {
+  ["O"]=>
+  string(6) "Orange"
+  ["O1"]=>
+  string(7) "Orange1"
+  ["O3"]=>
+  string(7) "Orange3"
+  ["b"]=>
+  string(6) "banana"
+  ["l"]=>
+  string(5) "lemon"
+  ["o"]=>
+  string(6) "orange"
+  ["o2"]=>
+  string(7) "orange2"
+  ["o20"]=>
+  string(8) "orange20"
+}
+
+-- Testing asort() by supplying string array (natural, case insensitive), 'flag' = SORT_NATURAL|SORT_FLAG_CASE --
+bool(true)
+array(8) {
   ["b"]=>
   string(6) "banana"
   ["l"]=>
   string(5) "lemon"
   ["o"]=>
   string(6) "orange"
+  ["O"]=>
+  string(6) "Orange"
+  ["O1"]=>
+  string(7) "Orange1"
+  ["o2"]=>
+  string(7) "orange2"
+  ["O3"]=>
+  string(7) "Orange3"
+  ["o20"]=>
+  string(8) "orange20"
 }
 
 -- Testing asort() by supplying numeric array, 'flag' = SORT_NUMERIC --
@@ -130,4 +242,4 @@ array(4) {
   [3]=>
   int(555)
 }
-Done
+Done
\ No newline at end of file
index 07dfe9b81547efc45973ddb1072cb4a670f47a05..6cce644331cddd6c40624e937ff42b0b681ee651 100644 (file)
@@ -102,10 +102,10 @@ array(3) {
 -- Iteration 2 --
 bool(true)
 array(3) {
-  [2]=>
-  int(2)
   [1]=>
   int(10)
+  [2]=>
+  int(2)
   [3]=>
   int(45)
 }
index 913256897b6a9593cd4746d4c1a89cdff0d6e2dc..27361eb96d4828b8fbe0da32c1e3a762d346acad 100644 (file)
@@ -20,6 +20,11 @@ echo "*** Testing krsort() : basic functionality ***\n";
 
 // an array containing unsorted string values with indices  
 $unsorted_strings =   array( "lemon" => "l", "orange" => "o", "banana" => "b" ); 
+$unsorted_strings = array(
+       "l" => "lemon", "o" => "orange",
+       "O" => "Orange", "O1" => "Orange1", "o2" => "orange2", "O3" => "Orange3", "o20" => "orange20",
+       "b" => "banana",
+);
 // an array containing unsorted numeric values with indices 
 $unsorted_numerics =  array( 100 => 4, 33 => 3, 555 => 2, 22 => 1 );
 
@@ -48,6 +53,21 @@ $temp_array = $unsorted_strings;
 var_dump( krsort($temp_array, SORT_STRING) ); // expecting : bool(true)
 var_dump( $temp_array);
 
+echo "\n-- Testing krsort() by supplying string array (case insensitive), 'flag' = SORT_STRING|SORT_FLAG_CASE --\n";
+$temp_array = $unsorted_strings;
+var_dump( krsort($temp_array, SORT_STRING|SORT_FLAG_CASE) ); // expecting : bool(true)
+var_dump( $temp_array);
+
+echo "\n-- Testing krsort() by supplying string array (natural), 'flag' = SORT_NATURAL --\n";
+$temp_array = $unsorted_strings;
+var_dump( krsort($temp_array, SORT_NATURAL) ); // expecting : bool(true)
+var_dump( $temp_array);
+
+echo "\n-- Testing krsort() by supplying string array (natural, case insensitive), 'flag' = SORT_NATURAL|SORT_FLAG_CASE --\n";
+$temp_array = $unsorted_strings;
+var_dump( krsort($temp_array, SORT_NATURAL|SORT_FLAG_CASE) ); // 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)
@@ -60,13 +80,23 @@ echo "Done\n";
 
 -- 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"
+array(8) {
+  ["o20"]=>
+  string(8) "orange20"
+  ["o2"]=>
+  string(7) "orange2"
+  ["o"]=>
+  string(6) "orange"
+  ["l"]=>
+  string(5) "lemon"
+  ["b"]=>
+  string(6) "banana"
+  ["O3"]=>
+  string(7) "Orange3"
+  ["O1"]=>
+  string(7) "Orange1"
+  ["O"]=>
+  string(6) "Orange"
 }
 
 -- Testing krsort() by supplying numeric array, 'flag' value is defualt --
@@ -84,13 +114,23 @@ array(4) {
 
 -- 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"
+array(8) {
+  ["o20"]=>
+  string(8) "orange20"
+  ["o2"]=>
+  string(7) "orange2"
+  ["o"]=>
+  string(6) "orange"
+  ["l"]=>
+  string(5) "lemon"
+  ["b"]=>
+  string(6) "banana"
+  ["O3"]=>
+  string(7) "Orange3"
+  ["O1"]=>
+  string(7) "Orange1"
+  ["O"]=>
+  string(6) "Orange"
 }
 
 -- Testing krsort() by supplying numeric array, 'flag' = SORT_REGULAR --
@@ -108,13 +148,86 @@ array(4) {
 
 -- 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"
+array(8) {
+  ["o20"]=>
+  string(8) "orange20"
+  ["o2"]=>
+  string(7) "orange2"
+  ["o"]=>
+  string(6) "orange"
+  ["l"]=>
+  string(5) "lemon"
+  ["b"]=>
+  string(6) "banana"
+  ["O3"]=>
+  string(7) "Orange3"
+  ["O1"]=>
+  string(7) "Orange1"
+  ["O"]=>
+  string(6) "Orange"
+}
+
+-- Testing krsort() by supplying string array (case insensitive), 'flag' = SORT_STRING|SORT_FLAG_CASE --
+bool(true)
+array(8) {
+  ["O3"]=>
+  string(7) "Orange3"
+  ["o20"]=>
+  string(8) "orange20"
+  ["o2"]=>
+  string(7) "orange2"
+  ["O1"]=>
+  string(7) "Orange1"
+  ["o"]=>
+  string(6) "orange"
+  ["O"]=>
+  string(6) "Orange"
+  ["l"]=>
+  string(5) "lemon"
+  ["b"]=>
+  string(6) "banana"
+}
+
+-- Testing krsort() by supplying string array (natural), 'flag' = SORT_NATURAL --
+bool(true)
+array(8) {
+  ["o20"]=>
+  string(8) "orange20"
+  ["o2"]=>
+  string(7) "orange2"
+  ["o"]=>
+  string(6) "orange"
+  ["l"]=>
+  string(5) "lemon"
+  ["b"]=>
+  string(6) "banana"
+  ["O3"]=>
+  string(7) "Orange3"
+  ["O1"]=>
+  string(7) "Orange1"
+  ["O"]=>
+  string(6) "Orange"
+}
+
+-- Testing krsort() by supplying string array (natural, case insensitive), 'flag' = SORT_NATURAL|SORT_FLAG_CASE --
+bool(true)
+array(8) {
+  ["o20"]=>
+  string(8) "orange20"
+  ["O3"]=>
+  string(7) "Orange3"
+  ["o2"]=>
+  string(7) "orange2"
+  ["O1"]=>
+  string(7) "Orange1"
+  ["o"]=>
+  string(6) "orange"
+  ["O"]=>
+  string(6) "Orange"
+  ["l"]=>
+  string(5) "lemon"
+  ["b"]=>
+  string(6) "banana"
 }
 
 -- Testing krsort() by supplying numeric array, 'flag' = SORT_NUMERIC --
@@ -129,4 +242,4 @@ array(4) {
   [22]=>
   int(1)
 }
-Done
+Done
\ No newline at end of file
index c567f766cb614d594c8295bc447b34f97aa20801..13762024705ebc540f2d5877c853ce2f641f0efe 100644 (file)
@@ -103,10 +103,10 @@ bool(true)
 array(3) {
   [45]=>
   int(45)
-  [10]=>
-  int(10)
   [2]=>
   int(2)
+  [10]=>
+  int(10)
 }
 -- Iteration 3 --
 bool(true)
index fdc8bd8dc69a04379ef54c9f0f0bc114d9469214..dd9f7a2158223aa907398cbdb27efa1f6513667e 100644 (file)
@@ -18,7 +18,11 @@ Test ksort() function : basic functionality
 echo "*** Testing ksort() : basic functionality ***\n";
 
 // an array containing unsorted string values with indices  
-$unsorted_strings =   array( "lemon" => "l", "orange" => "o", "banana" => "b" ); 
+$unsorted_strings =   array(
+       "l" => "lemon", "o" => "orange",
+       "O" => "Orange", "O1" => "Orange1", "o2" => "orange2", "O3" => "Orange3", "o20" => "orange20",
+       "b" => "banana",
+);
 // an array containing unsorted numeric values with indices 
 $unsorted_numerics =  array( 100 => 4, 33 => 3, 555 => 2, 22 => 1 );
 
@@ -47,6 +51,21 @@ $temp_array = $unsorted_strings;
 var_dump( ksort($temp_array, SORT_STRING) ); // expecting : bool(true)
 var_dump( $temp_array);
 
+echo "\n-- Testing ksort() by supplying string array (case insensitive), 'flag' = SORT_STRING|SORT_FLAG_CASE --\n";
+$temp_array = $unsorted_strings;
+var_dump( sort($temp_array, SORT_STRING|SORT_FLAG_CASE) ); // expecting : bool(true)
+var_dump( $temp_array);
+
+echo "\n-- Testing ksort() by supplying string array (natural), 'flag' = SORT_NATURAL --\n";
+$temp_array = $unsorted_strings;
+var_dump( sort($temp_array, SORT_NATURAL) ); // expecting : bool(true)
+var_dump( $temp_array);
+
+echo "\n-- Testing ksort() by supplying string array (natural, case insensitive), 'flag' = SORT_NATURAL|SORT_FLAG_CASE --\n";
+$temp_array = $unsorted_strings;
+var_dump( sort($temp_array, SORT_NATURAL|SORT_FLAG_CASE) ); // expecting : bool(true)
+var_dump( $temp_array);
+
 echo "\n-- Testing ksort() by supplying numeric array, 'flag' = SORT_NUMERIC --\n";
 $temp_array = $unsorted_numerics;
 var_dump( ksort($temp_array, SORT_NUMERIC) ); // expecting : bool(true)
@@ -59,13 +78,23 @@ echo "Done\n";
 
 -- Testing ksort() by supplying string array, 'flag' value is defualt --
 bool(true)
-array(3) {
-  ["banana"]=>
-  string(1) "b"
-  ["lemon"]=>
-  string(1) "l"
-  ["orange"]=>
-  string(1) "o"
+array(8) {
+  ["O"]=>
+  string(6) "Orange"
+  ["O1"]=>
+  string(7) "Orange1"
+  ["O3"]=>
+  string(7) "Orange3"
+  ["b"]=>
+  string(6) "banana"
+  ["l"]=>
+  string(5) "lemon"
+  ["o"]=>
+  string(6) "orange"
+  ["o2"]=>
+  string(7) "orange2"
+  ["o20"]=>
+  string(8) "orange20"
 }
 
 -- Testing ksort() by supplying numeric array, 'flag' value is defualt --
@@ -83,13 +112,23 @@ array(4) {
 
 -- Testing ksort() by supplying string array, 'flag' = SORT_REGULAR --
 bool(true)
-array(3) {
-  ["banana"]=>
-  string(1) "b"
-  ["lemon"]=>
-  string(1) "l"
-  ["orange"]=>
-  string(1) "o"
+array(8) {
+  ["O"]=>
+  string(6) "Orange"
+  ["O1"]=>
+  string(7) "Orange1"
+  ["O3"]=>
+  string(7) "Orange3"
+  ["b"]=>
+  string(6) "banana"
+  ["l"]=>
+  string(5) "lemon"
+  ["o"]=>
+  string(6) "orange"
+  ["o2"]=>
+  string(7) "orange2"
+  ["o20"]=>
+  string(8) "orange20"
 }
 
 -- Testing ksort() by supplying numeric array, 'flag' = SORT_REGULAR --
@@ -107,13 +146,86 @@ array(4) {
 
 -- Testing ksort() by supplying string array, 'flag' = SORT_STRING --
 bool(true)
-array(3) {
-  ["banana"]=>
-  string(1) "b"
-  ["lemon"]=>
-  string(1) "l"
-  ["orange"]=>
-  string(1) "o"
+array(8) {
+  ["O"]=>
+  string(6) "Orange"
+  ["O1"]=>
+  string(7) "Orange1"
+  ["O3"]=>
+  string(7) "Orange3"
+  ["b"]=>
+  string(6) "banana"
+  ["l"]=>
+  string(5) "lemon"
+  ["o"]=>
+  string(6) "orange"
+  ["o2"]=>
+  string(7) "orange2"
+  ["o20"]=>
+  string(8) "orange20"
+}
+
+-- Testing ksort() by supplying string array (case insensitive), 'flag' = SORT_STRING|SORT_FLAG_CASE --
+bool(true)
+array(8) {
+  [0]=>
+  string(6) "banana"
+  [1]=>
+  string(5) "lemon"
+  [2]=>
+  string(6) "orange"
+  [3]=>
+  string(6) "Orange"
+  [4]=>
+  string(7) "Orange1"
+  [5]=>
+  string(7) "orange2"
+  [6]=>
+  string(8) "orange20"
+  [7]=>
+  string(7) "Orange3"
+}
+
+-- Testing ksort() by supplying string array (natural), 'flag' = SORT_NATURAL --
+bool(true)
+array(8) {
+  [0]=>
+  string(6) "Orange"
+  [1]=>
+  string(7) "Orange1"
+  [2]=>
+  string(7) "Orange3"
+  [3]=>
+  string(6) "banana"
+  [4]=>
+  string(5) "lemon"
+  [5]=>
+  string(6) "orange"
+  [6]=>
+  string(7) "orange2"
+  [7]=>
+  string(8) "orange20"
+}
+
+-- Testing ksort() by supplying string array (natural, case insensitive), 'flag' = SORT_NATURAL|SORT_FLAG_CASE --
+bool(true)
+array(8) {
+  [0]=>
+  string(6) "banana"
+  [1]=>
+  string(5) "lemon"
+  [2]=>
+  string(6) "orange"
+  [3]=>
+  string(6) "Orange"
+  [4]=>
+  string(7) "Orange1"
+  [5]=>
+  string(7) "orange2"
+  [6]=>
+  string(7) "Orange3"
+  [7]=>
+  string(8) "orange20"
 }
 
 -- Testing ksort() by supplying numeric array, 'flag' = SORT_NUMERIC --
@@ -128,4 +240,4 @@ array(4) {
   [555]=>
   int(2)
 }
-Done
+Done
\ No newline at end of file
index f765977d21b13f05071901fa342e69413300c7b2..4969844e759d26801cc3c2893bfed2d2af383711 100644 (file)
@@ -101,10 +101,10 @@ array(3) {
 -- Iteration 2 --
 bool(true)
 array(3) {
-  [2]=>
-  int(2)
   [10]=>
   int(10)
+  [2]=>
+  int(2)
   [45]=>
   int(45)
 }
index 5495be92571a195944457976d7174a1be0498c76..34fcbb7034f9e4bfa28a95f61c7bd1c140e6b1a7 100644 (file)
@@ -14,7 +14,11 @@ Test rsort() function : basic functionality
 echo "*** Testing rsort() : basic functionality ***\n";
 
 // associative array containing unsorted string values  
-$unsorted_strings =   array( "l" => "lemon", "o" => "orange", "b" => "banana" );
+$unsorted_strings = array(
+       "l" => "lemon", "o" => "orange",
+       "O" => "Orange", "O1" => "Orange1", "o2" => "orange2", "O3" => "Orange3", "o20" => "orange20",
+       "b" => "banana",
+);
  
 // array with default keys containing unsorted numeric values
 $unsorted_numerics =  array( 100, 33, 555, 22 );
@@ -44,6 +48,21 @@ $temp_array = $unsorted_strings;
 var_dump( rsort($temp_array, SORT_STRING) );
 var_dump( $temp_array);
 
+echo "\n-- Testing rsort() by supplying string array (case insensitive), 'flag' = SORT_STRING|SORT_FLAG_CASE --\n";
+$temp_array = $unsorted_strings;
+var_dump( rsort($temp_array, SORT_STRING|SORT_FLAG_CASE) ); // expecting : bool(true)
+var_dump( $temp_array);
+
+echo "\n-- Testing rsort() by supplying string array (natural), 'flag' = SORT_NATURAL --\n";
+$temp_array = $unsorted_strings;
+var_dump( rsort($temp_array, SORT_NATURAL) ); // expecting : bool(true)
+var_dump( $temp_array);
+
+echo "\n-- Testing rsort() by supplying string array (natural, case insensitive), 'flag' = SORT_NATURAL|SORT_FLAG_CASE --\n";
+$temp_array = $unsorted_strings;
+var_dump( rsort($temp_array, SORT_NATURAL|SORT_FLAG_CASE) ); // expecting : bool(true)
+var_dump( $temp_array);
+
 echo "\n-- Testing rsort() by supplying numeric array, 'flag' = SORT_NUMERIC --\n";
 $temp_array = $unsorted_numerics;
 var_dump( rsort($temp_array, SORT_NUMERIC) );
@@ -57,13 +76,23 @@ echo "Done";
 
 -- Testing rsort() by supplying string array, 'flag' value is defualt --
 bool(true)
-array(3) {
+array(8) {
   [0]=>
-  string(6) "orange"
+  string(8) "orange20"
   [1]=>
-  string(5) "lemon"
+  string(7) "orange2"
   [2]=>
+  string(6) "orange"
+  [3]=>
+  string(5) "lemon"
+  [4]=>
   string(6) "banana"
+  [5]=>
+  string(7) "Orange3"
+  [6]=>
+  string(7) "Orange1"
+  [7]=>
+  string(6) "Orange"
 }
 
 -- Testing rsort() by supplying numeric array, 'flag' value is defualt --
@@ -81,13 +110,23 @@ array(4) {
 
 -- Testing rsort() by supplying string array, 'flag' = SORT_REGULAR --
 bool(true)
-array(3) {
+array(8) {
   [0]=>
-  string(6) "orange"
+  string(8) "orange20"
   [1]=>
-  string(5) "lemon"
+  string(7) "orange2"
   [2]=>
+  string(6) "orange"
+  [3]=>
+  string(5) "lemon"
+  [4]=>
   string(6) "banana"
+  [5]=>
+  string(7) "Orange3"
+  [6]=>
+  string(7) "Orange1"
+  [7]=>
+  string(6) "Orange"
 }
 
 -- Testing rsort() by supplying numeric array, 'flag' = SORT_REGULAR --
@@ -105,12 +144,85 @@ array(4) {
 
 -- Testing rsort() by supplying string array, 'flag' = SORT_STRING --
 bool(true)
-array(3) {
+array(8) {
+  [0]=>
+  string(8) "orange20"
+  [1]=>
+  string(7) "orange2"
+  [2]=>
+  string(6) "orange"
+  [3]=>
+  string(5) "lemon"
+  [4]=>
+  string(6) "banana"
+  [5]=>
+  string(7) "Orange3"
+  [6]=>
+  string(7) "Orange1"
+  [7]=>
+  string(6) "Orange"
+}
+
+-- Testing rsort() by supplying string array (case insensitive), 'flag' = SORT_STRING|SORT_FLAG_CASE --
+bool(true)
+array(8) {
   [0]=>
+  string(7) "Orange3"
+  [1]=>
+  string(8) "orange20"
+  [2]=>
+  string(7) "orange2"
+  [3]=>
+  string(7) "Orange1"
+  [4]=>
   string(6) "orange"
+  [5]=>
+  string(6) "Orange"
+  [6]=>
+  string(5) "lemon"
+  [7]=>
+  string(6) "banana"
+}
+
+-- Testing rsort() by supplying string array (natural), 'flag' = SORT_NATURAL --
+bool(true)
+array(8) {
+  [0]=>
+  string(8) "orange20"
   [1]=>
+  string(7) "orange2"
+  [2]=>
+  string(6) "orange"
+  [3]=>
   string(5) "lemon"
+  [4]=>
+  string(6) "banana"
+  [5]=>
+  string(7) "Orange3"
+  [6]=>
+  string(7) "Orange1"
+  [7]=>
+  string(6) "Orange"
+}
+
+-- Testing rsort() by supplying string array (natural, case insensitive), 'flag' = SORT_NATURAL|SORT_FLAG_CASE --
+bool(true)
+array(8) {
+  [0]=>
+  string(8) "orange20"
+  [1]=>
+  string(7) "Orange3"
   [2]=>
+  string(7) "orange2"
+  [3]=>
+  string(7) "Orange1"
+  [4]=>
+  string(6) "orange"
+  [5]=>
+  string(6) "Orange"
+  [6]=>
+  string(5) "lemon"
+  [7]=>
   string(6) "banana"
 }
 
index 3cf653f2089263d1fae02fc8e9841b3635f04e5e..460b572fc14c84feeafff73632b883ab505c34f5 100644 (file)
@@ -20,7 +20,11 @@ Test sort() function : basic functionality
 echo "*** Testing sort() : basic functionality ***\n";
 
 // associative array containing unsorted string values  
-$unsorted_strings =   array( "l" => "lemon", "o" => "orange", "b" => "banana" );
+$unsorted_strings = array(
+       "l" => "lemon", "o" => "orange",
+       "O" => "Orange", "O1" => "Orange1", "o2" => "orange2", "O3" => "Orange3", "o20" => "orange20",
+       "b" => "banana",
+);
  
 // array with default keys containing unsorted numeric values
 $unsorted_numerics =  array( 100, 33, 555, 22 );
@@ -50,6 +54,21 @@ $temp_array = $unsorted_strings;
 var_dump( sort($temp_array, SORT_STRING) ); // expecting : bool(true)
 var_dump( $temp_array);
 
+echo "\n-- Testing sort() by supplying string array (case insensitive), 'flag' = SORT_STRING|SORT_FLAG_CASE --\n";
+$temp_array = $unsorted_strings;
+var_dump( sort($temp_array, SORT_STRING|SORT_FLAG_CASE) ); // expecting : bool(true)
+var_dump( $temp_array);
+
+echo "\n-- Testing sort() by supplying string array (natural), 'flag' = SORT_NATURAL --\n";
+$temp_array = $unsorted_strings;
+var_dump( sort($temp_array, SORT_NATURAL) ); // expecting : bool(true)
+var_dump( $temp_array);
+
+echo "\n-- Testing sort() by supplying string array (natural, case insensitive), 'flag' = SORT_NATURAL|SORT_FLAG_CASE --\n";
+$temp_array = $unsorted_strings;
+var_dump( sort($temp_array, SORT_NATURAL|SORT_FLAG_CASE) ); // expecting : bool(true)
+var_dump( $temp_array);
+
 echo "\n-- Testing sort() by supplying numeric array, 'flag' = SORT_NUMERIC --\n";
 $temp_array = $unsorted_numerics;
 var_dump( sort($temp_array, SORT_NUMERIC) ); // expecting : bool(true)
@@ -62,13 +81,23 @@ echo "Done\n";
 
 -- Testing sort() by supplying string array, 'flag' value is defualt --
 bool(true)
-array(3) {
+array(8) {
   [0]=>
-  string(6) "banana"
+  string(6) "Orange"
   [1]=>
-  string(5) "lemon"
+  string(7) "Orange1"
   [2]=>
+  string(7) "Orange3"
+  [3]=>
+  string(6) "banana"
+  [4]=>
+  string(5) "lemon"
+  [5]=>
   string(6) "orange"
+  [6]=>
+  string(7) "orange2"
+  [7]=>
+  string(8) "orange20"
 }
 
 -- Testing sort() by supplying numeric array, 'flag' value is defualt --
@@ -86,13 +115,23 @@ array(4) {
 
 -- Testing sort() by supplying string array, 'flag' = SORT_REGULAR --
 bool(true)
-array(3) {
+array(8) {
   [0]=>
-  string(6) "banana"
+  string(6) "Orange"
   [1]=>
-  string(5) "lemon"
+  string(7) "Orange1"
   [2]=>
+  string(7) "Orange3"
+  [3]=>
+  string(6) "banana"
+  [4]=>
+  string(5) "lemon"
+  [5]=>
   string(6) "orange"
+  [6]=>
+  string(7) "orange2"
+  [7]=>
+  string(8) "orange20"
 }
 
 -- Testing sort() by supplying numeric array, 'flag' = SORT_REGULAR --
@@ -110,13 +149,86 @@ array(4) {
 
 -- Testing sort() by supplying string array, 'flag' = SORT_STRING --
 bool(true)
-array(3) {
+array(8) {
+  [0]=>
+  string(6) "Orange"
+  [1]=>
+  string(7) "Orange1"
+  [2]=>
+  string(7) "Orange3"
+  [3]=>
+  string(6) "banana"
+  [4]=>
+  string(5) "lemon"
+  [5]=>
+  string(6) "orange"
+  [6]=>
+  string(7) "orange2"
+  [7]=>
+  string(8) "orange20"
+}
+
+-- Testing sort() by supplying string array (case insensitive), 'flag' = SORT_STRING|SORT_FLAG_CASE --
+bool(true)
+array(8) {
   [0]=>
   string(6) "banana"
   [1]=>
   string(5) "lemon"
   [2]=>
   string(6) "orange"
+  [3]=>
+  string(6) "Orange"
+  [4]=>
+  string(7) "Orange1"
+  [5]=>
+  string(7) "orange2"
+  [6]=>
+  string(8) "orange20"
+  [7]=>
+  string(7) "Orange3"
+}
+
+-- Testing sort() by supplying string array (natural), 'flag' = SORT_NATURAL --
+bool(true)
+array(8) {
+  [0]=>
+  string(6) "Orange"
+  [1]=>
+  string(7) "Orange1"
+  [2]=>
+  string(7) "Orange3"
+  [3]=>
+  string(6) "banana"
+  [4]=>
+  string(5) "lemon"
+  [5]=>
+  string(6) "orange"
+  [6]=>
+  string(7) "orange2"
+  [7]=>
+  string(8) "orange20"
+}
+
+-- Testing sort() by supplying string array (natural, case insensitive), 'flag' = SORT_NATURAL|SORT_FLAG_CASE --
+bool(true)
+array(8) {
+  [0]=>
+  string(6) "banana"
+  [1]=>
+  string(5) "lemon"
+  [2]=>
+  string(6) "orange"
+  [3]=>
+  string(6) "Orange"
+  [4]=>
+  string(7) "Orange1"
+  [5]=>
+  string(7) "orange2"
+  [6]=>
+  string(7) "Orange3"
+  [7]=>
+  string(8) "orange20"
 }
 
 -- Testing sort() by supplying numeric array, 'flag' = SORT_NUMERIC --
@@ -131,4 +243,4 @@ array(4) {
   [3]=>
   int(555)
 }
-Done
+Done
\ No newline at end of file
index 4304ecb7674e2d03d5bf29a50795eddf71f76bb7..7cb8ed642a83a583dcf46d7d3952602a48dcf35c 100644 (file)
@@ -106,9 +106,9 @@ array(3) {
 bool(true)
 array(3) {
   [0]=>
-  int(2)
-  [1]=>
   int(10)
+  [1]=>
+  int(2)
   [2]=>
   int(45)
 }