add support for SORT_NATURAL and SORT_FLAG_CASE in array sort functions

This commit is contained in:
Arpad Ray 2011-08-29 20:23:34 +00:00
parent a34e9efcfa
commit 4a6c2a8b44
35 changed files with 1187 additions and 103 deletions

2
NEWS
View File

@ -54,6 +54,8 @@ PHP NEWS
one SAPI module the same time. FR #53271, FR #52410. (Jani)
. Added optional argument to debug_backtrace() and debug_print_backtrace()
to limit the amount of stack frames returned. (Sebastian, Patrick)
. 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 Zend Engine memory usage: (Dmitry)
. Replaced zend_function.pass_rest_by_reference by

View 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

View 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];

View 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

View 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)

View 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:

View 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:

View File

@ -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===

View 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:

View File

@ -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===

View File

@ -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===

View File

@ -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===

View File

@ -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===

View 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:

View 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:

View 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:

View 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";

View 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:

View 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:

View 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:

View 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:

View 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:

View 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:

View 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:

View 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,13 +148,86 @@ 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"]=>
string(6) "banana"
}
-- Testing arsort() by supplying numeric array, 'flag' = SORT_NUMERIC --

View 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
Done

View 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

View 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)
}

View 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

View 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)

View 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

View 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)
}

View 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(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 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"
}

View 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

View File

@ -106,9 +106,9 @@ array(3) {
bool(true)
array(3) {
[0]=>
int(2)
[1]=>
int(10)
[1]=>
int(2)
[2]=>
int(45)
}