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