mirror of
https://github.com/php/php-src.git
synced 2025-01-08 20:17:28 +08:00
New testcases for array_merge_recursive() function
This commit is contained in:
parent
922d1fce29
commit
5ce6116777
97
ext/standard/tests/array/array_merge_recursive_basic1.phpt
Normal file
97
ext/standard/tests/array/array_merge_recursive_basic1.phpt
Normal file
@ -0,0 +1,97 @@
|
||||
--TEST--
|
||||
Test array_merge_recursive() function : basic functionality - array with default keys
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : array array_merge_recursive(array $arr1[, array $...])
|
||||
* Description: Recursively merges elements from passed arrays into one array
|
||||
* Source code: ext/standard/array.c
|
||||
*/
|
||||
|
||||
echo "*** Testing array_merge_recursive() : array with default keys ***\n";
|
||||
|
||||
// Initialise the arrays
|
||||
$arr1 = array(1, array(1, 2));
|
||||
$arr2 = array(3, array("hello", 'world'));
|
||||
$arr3 = array(array(6, 7), array("str1", 'str2'));
|
||||
|
||||
// Calling array_merge_recursive() with default arguments
|
||||
echo "-- With default argument --\n";
|
||||
var_dump( array_merge_recursive($arr1) );
|
||||
|
||||
// Calling array_merge_recursive() with more arguments
|
||||
echo "-- With more arguments --\n";
|
||||
var_dump( array_merge_recursive($arr1,$arr2) );
|
||||
var_dump( array_merge_recursive($arr1,$arr2,$arr3) );
|
||||
|
||||
echo "Done";
|
||||
?>
|
||||
--EXPECTF--
|
||||
*** Testing array_merge_recursive() : array with default keys ***
|
||||
-- With default argument --
|
||||
array(2) {
|
||||
[0]=>
|
||||
int(1)
|
||||
[1]=>
|
||||
array(2) {
|
||||
[0]=>
|
||||
int(1)
|
||||
[1]=>
|
||||
int(2)
|
||||
}
|
||||
}
|
||||
-- With more arguments --
|
||||
array(4) {
|
||||
[0]=>
|
||||
int(1)
|
||||
[1]=>
|
||||
array(2) {
|
||||
[0]=>
|
||||
int(1)
|
||||
[1]=>
|
||||
int(2)
|
||||
}
|
||||
[2]=>
|
||||
int(3)
|
||||
[3]=>
|
||||
array(2) {
|
||||
[0]=>
|
||||
string(5) "hello"
|
||||
[1]=>
|
||||
string(5) "world"
|
||||
}
|
||||
}
|
||||
array(6) {
|
||||
[0]=>
|
||||
int(1)
|
||||
[1]=>
|
||||
array(2) {
|
||||
[0]=>
|
||||
int(1)
|
||||
[1]=>
|
||||
int(2)
|
||||
}
|
||||
[2]=>
|
||||
int(3)
|
||||
[3]=>
|
||||
array(2) {
|
||||
[0]=>
|
||||
string(5) "hello"
|
||||
[1]=>
|
||||
string(5) "world"
|
||||
}
|
||||
[4]=>
|
||||
array(2) {
|
||||
[0]=>
|
||||
int(6)
|
||||
[1]=>
|
||||
int(7)
|
||||
}
|
||||
[5]=>
|
||||
array(2) {
|
||||
[0]=>
|
||||
string(4) "str1"
|
||||
[1]=>
|
||||
string(4) "str2"
|
||||
}
|
||||
}
|
||||
Done
|
94
ext/standard/tests/array/array_merge_recursive_basic2.phpt
Normal file
94
ext/standard/tests/array/array_merge_recursive_basic2.phpt
Normal file
@ -0,0 +1,94 @@
|
||||
--TEST--
|
||||
Test array_merge_recursive() function : basic functionality - associative arrays
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : array array_merge_recursive(array $arr1[, array $...])
|
||||
* Description: Recursively merges elements from passed arrays into one array
|
||||
* Source code: ext/standard/array.c
|
||||
*/
|
||||
|
||||
echo "*** Testing array_merge_recursive() : associative arrays ***\n";
|
||||
|
||||
// Initialise the arrays
|
||||
$arr1 = array(1 => "one", 2 => array(1, 2));
|
||||
$arr2 = array(2 => 'three', "four" => array("hello", 'world'));
|
||||
$arr3 = array(1 => array(6, 7), 'four' => array("str1", 'str2'));
|
||||
|
||||
// Calling array_merge_recursive() with default arguments
|
||||
echo "-- With default argument --\n";
|
||||
var_dump( array_merge_recursive($arr1) );
|
||||
|
||||
// Calling array_merge_recursive() with more arguments
|
||||
echo "-- With more arguments --\n";
|
||||
var_dump( array_merge_recursive($arr1,$arr2) );
|
||||
var_dump( array_merge_recursive($arr1,$arr2,$arr3) );
|
||||
|
||||
echo "Done";
|
||||
?>
|
||||
--EXPECTF--
|
||||
*** Testing array_merge_recursive() : associative arrays ***
|
||||
-- With default argument --
|
||||
array(2) {
|
||||
[0]=>
|
||||
string(3) "one"
|
||||
[1]=>
|
||||
array(2) {
|
||||
[0]=>
|
||||
int(1)
|
||||
[1]=>
|
||||
int(2)
|
||||
}
|
||||
}
|
||||
-- With more arguments --
|
||||
array(4) {
|
||||
[0]=>
|
||||
string(3) "one"
|
||||
[1]=>
|
||||
array(2) {
|
||||
[0]=>
|
||||
int(1)
|
||||
[1]=>
|
||||
int(2)
|
||||
}
|
||||
[2]=>
|
||||
string(5) "three"
|
||||
["four"]=>
|
||||
array(2) {
|
||||
[0]=>
|
||||
string(5) "hello"
|
||||
[1]=>
|
||||
string(5) "world"
|
||||
}
|
||||
}
|
||||
array(5) {
|
||||
[0]=>
|
||||
string(3) "one"
|
||||
[1]=>
|
||||
array(2) {
|
||||
[0]=>
|
||||
int(1)
|
||||
[1]=>
|
||||
int(2)
|
||||
}
|
||||
[2]=>
|
||||
string(5) "three"
|
||||
["four"]=>
|
||||
array(4) {
|
||||
[0]=>
|
||||
string(5) "hello"
|
||||
[1]=>
|
||||
string(5) "world"
|
||||
[2]=>
|
||||
string(4) "str1"
|
||||
[3]=>
|
||||
string(4) "str2"
|
||||
}
|
||||
[3]=>
|
||||
array(2) {
|
||||
[0]=>
|
||||
int(6)
|
||||
[1]=>
|
||||
int(7)
|
||||
}
|
||||
}
|
||||
Done
|
25
ext/standard/tests/array/array_merge_recursive_error.phpt
Normal file
25
ext/standard/tests/array/array_merge_recursive_error.phpt
Normal file
@ -0,0 +1,25 @@
|
||||
--TEST--
|
||||
Test array_merge_recursive() function : error conditions
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : array array_merge_recursive(array $arr1[, array $...])
|
||||
* Description: Recursively merges elements from passed arrays into one array
|
||||
* Source code: ext/standard/array.c
|
||||
*/
|
||||
|
||||
echo "*** Testing array_merge_recursive() : error conditions ***\n";
|
||||
|
||||
// Zero arguments
|
||||
echo "\n-- Testing array_merge_recursive() function with Zero arguments --\n";
|
||||
var_dump( array_merge_recursive() );
|
||||
|
||||
echo "Done";
|
||||
?>
|
||||
--EXPECTF--
|
||||
*** Testing array_merge_recursive() : error conditions ***
|
||||
|
||||
-- Testing array_merge_recursive() function with Zero arguments --
|
||||
|
||||
Warning: Wrong parameter count for array_merge_recursive() in %s on line %d
|
||||
NULL
|
||||
Done
|
303
ext/standard/tests/array/array_merge_recursive_variation1.phpt
Normal file
303
ext/standard/tests/array/array_merge_recursive_variation1.phpt
Normal file
@ -0,0 +1,303 @@
|
||||
--TEST--
|
||||
Test array_merge_recursive() function : usage variations - unexpected values for $arr1 argument
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : array array_merge_recursive(array $arr1[, array $...])
|
||||
* Description: Recursively merges elements from passed arrays into one array
|
||||
* Source code: ext/standard/array.c
|
||||
*/
|
||||
|
||||
/*
|
||||
* Passing non array values to 'arr1' argument of array_merge_recursive() and see
|
||||
* that the function outputs proper warning messages wherever expected.
|
||||
*/
|
||||
|
||||
echo "*** Testing array_merge_recursive() : Passing non array values to \$arr1 argument ***\n";
|
||||
|
||||
//get an unset variable
|
||||
$unset_var = 10;
|
||||
unset($unset_var);
|
||||
|
||||
class A
|
||||
{
|
||||
// public $var = 10;
|
||||
public function __toString() {
|
||||
return "object";
|
||||
}
|
||||
}
|
||||
|
||||
// heredoc string
|
||||
$heredoc = <<<EOT
|
||||
hello world
|
||||
EOT;
|
||||
|
||||
// get a resource variable
|
||||
$fp = fopen(__FILE__, "r");
|
||||
|
||||
// unexpected values to be passed to $arr1 argument
|
||||
$arrays = array (
|
||||
|
||||
// int data
|
||||
/*1*/ 0,
|
||||
1,
|
||||
12345,
|
||||
-2345,
|
||||
|
||||
// float data
|
||||
/*5*/ 10.5,
|
||||
-10.5,
|
||||
12.3456789000e10,
|
||||
12.3456789000E-10,
|
||||
.5,
|
||||
|
||||
// null data
|
||||
/*10*/ NULL,
|
||||
null,
|
||||
|
||||
// boolean data
|
||||
/*12*/ true,
|
||||
false,
|
||||
TRUE,
|
||||
FALSE,
|
||||
|
||||
// empty data
|
||||
/*16*/ "",
|
||||
'',
|
||||
|
||||
// string data
|
||||
/*18*/ "string",
|
||||
'string',
|
||||
$heredoc,
|
||||
|
||||
// undefined data
|
||||
/*21*/ @$undefined_var,
|
||||
|
||||
// unset data
|
||||
/*22*/ @$unset_var,
|
||||
|
||||
// resource variable
|
||||
/*23*/ $fp,
|
||||
|
||||
// object data
|
||||
/*24*/ new A()
|
||||
);
|
||||
|
||||
// initialise the second argument
|
||||
$arr2 = array(1, array("hello", 'world'));
|
||||
|
||||
// loop through each element of $arrays and check the behavior of array_merge_recursive()
|
||||
$iterator = 1;
|
||||
foreach($arrays as $arr1) {
|
||||
echo "\n-- Iteration $iterator --";
|
||||
|
||||
// with default argument
|
||||
echo "\n-- With default argument --";
|
||||
var_dump( array_merge_recursive($arr1) );
|
||||
|
||||
// with more arguments
|
||||
echo "-- With more arguments --";
|
||||
var_dump( array_merge_recursive($arr1, $arr2) );
|
||||
|
||||
$iterator++;
|
||||
}
|
||||
|
||||
// close the file resource used
|
||||
fclose($fp);
|
||||
|
||||
echo "Done";
|
||||
?>
|
||||
--EXPECTF--
|
||||
*** Testing array_merge_recursive() : Passing non array values to $arr1 argument ***
|
||||
|
||||
-- Iteration 1 --
|
||||
-- With default argument --
|
||||
Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
-- With more arguments --
|
||||
Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
-- Iteration 2 --
|
||||
-- With default argument --
|
||||
Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
-- With more arguments --
|
||||
Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
-- Iteration 3 --
|
||||
-- With default argument --
|
||||
Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
-- With more arguments --
|
||||
Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
-- Iteration 4 --
|
||||
-- With default argument --
|
||||
Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
-- With more arguments --
|
||||
Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
-- Iteration 5 --
|
||||
-- With default argument --
|
||||
Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
-- With more arguments --
|
||||
Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
-- Iteration 6 --
|
||||
-- With default argument --
|
||||
Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
-- With more arguments --
|
||||
Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
-- Iteration 7 --
|
||||
-- With default argument --
|
||||
Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
-- With more arguments --
|
||||
Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
-- Iteration 8 --
|
||||
-- With default argument --
|
||||
Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
-- With more arguments --
|
||||
Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
-- Iteration 9 --
|
||||
-- With default argument --
|
||||
Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
-- With more arguments --
|
||||
Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
-- Iteration 10 --
|
||||
-- With default argument --
|
||||
Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
-- With more arguments --
|
||||
Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
-- Iteration 11 --
|
||||
-- With default argument --
|
||||
Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
-- With more arguments --
|
||||
Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
-- Iteration 12 --
|
||||
-- With default argument --
|
||||
Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
-- With more arguments --
|
||||
Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
-- Iteration 13 --
|
||||
-- With default argument --
|
||||
Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
-- With more arguments --
|
||||
Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
-- Iteration 14 --
|
||||
-- With default argument --
|
||||
Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
-- With more arguments --
|
||||
Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
-- Iteration 15 --
|
||||
-- With default argument --
|
||||
Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
-- With more arguments --
|
||||
Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
-- Iteration 16 --
|
||||
-- With default argument --
|
||||
Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
-- With more arguments --
|
||||
Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
-- Iteration 17 --
|
||||
-- With default argument --
|
||||
Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
-- With more arguments --
|
||||
Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
-- Iteration 18 --
|
||||
-- With default argument --
|
||||
Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
-- With more arguments --
|
||||
Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
-- Iteration 19 --
|
||||
-- With default argument --
|
||||
Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
-- With more arguments --
|
||||
Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
-- Iteration 20 --
|
||||
-- With default argument --
|
||||
Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
-- With more arguments --
|
||||
Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
-- Iteration 21 --
|
||||
-- With default argument --
|
||||
Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
-- With more arguments --
|
||||
Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
-- Iteration 22 --
|
||||
-- With default argument --
|
||||
Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
-- With more arguments --
|
||||
Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
-- Iteration 23 --
|
||||
-- With default argument --
|
||||
Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
-- With more arguments --
|
||||
Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
-- Iteration 24 --
|
||||
-- With default argument --
|
||||
Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
-- With more arguments --
|
||||
Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d
|
||||
NULL
|
||||
Done
|
174
ext/standard/tests/array/array_merge_recursive_variation10.phpt
Normal file
174
ext/standard/tests/array/array_merge_recursive_variation10.phpt
Normal file
@ -0,0 +1,174 @@
|
||||
--TEST--
|
||||
Test array_merge_recursive() function : usage variations - two dimensional arrays
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : array array_merge_recursive(array $arr1[, array $...])
|
||||
* Description: Recursively merges elements from passed arrays into one array
|
||||
* Source code: ext/standard/array.c
|
||||
*/
|
||||
|
||||
/*
|
||||
* Testing the functionality of array_merge_recursive() by passing
|
||||
* two dimensional arrays for $arr1 argument.
|
||||
*/
|
||||
|
||||
echo "*** Testing array_merge_recursive() : two dimensional array for \$arr1 argument ***\n";
|
||||
|
||||
// initialize the 2-d array
|
||||
$arr1 = array(
|
||||
array(1, 2, 3, 1),
|
||||
"array" => array("hello", "world", "str1" => "hello", "str2" => 'world'),
|
||||
array(1 => "one", 2 => "two", "one", 'two'),
|
||||
array(1, 2, 3, 1)
|
||||
);
|
||||
|
||||
// initialize the second argument
|
||||
$arr2 = array(1, "hello", "array" => array("hello", 'world'));
|
||||
|
||||
echo "-- Passing the entire 2-d array --\n";
|
||||
echo "-- With default argument --\n";
|
||||
var_dump( array_merge_recursive($arr1) );
|
||||
echo "-- With more arguments --\n";
|
||||
var_dump( array_merge_recursive($arr1, $arr2) );
|
||||
|
||||
echo "-- Passing the sub-array --\n";
|
||||
echo "-- With default argument --\n";
|
||||
var_dump( array_merge_recursive($arr1["array"]) );
|
||||
echo "-- With more arguments --\n";
|
||||
var_dump( array_merge_recursive($arr1["array"], $arr2["array"]) );
|
||||
|
||||
echo "Done";
|
||||
?>
|
||||
--EXPECTF--
|
||||
*** Testing array_merge_recursive() : two dimensional array for $arr1 argument ***
|
||||
-- Passing the entire 2-d array --
|
||||
-- With default argument --
|
||||
array(4) {
|
||||
[0]=>
|
||||
array(4) {
|
||||
[0]=>
|
||||
int(1)
|
||||
[1]=>
|
||||
int(2)
|
||||
[2]=>
|
||||
int(3)
|
||||
[3]=>
|
||||
int(1)
|
||||
}
|
||||
["array"]=>
|
||||
array(4) {
|
||||
[0]=>
|
||||
string(5) "hello"
|
||||
[1]=>
|
||||
string(5) "world"
|
||||
["str1"]=>
|
||||
string(5) "hello"
|
||||
["str2"]=>
|
||||
string(5) "world"
|
||||
}
|
||||
[1]=>
|
||||
array(4) {
|
||||
[1]=>
|
||||
string(3) "one"
|
||||
[2]=>
|
||||
string(3) "two"
|
||||
[3]=>
|
||||
string(3) "one"
|
||||
[4]=>
|
||||
string(3) "two"
|
||||
}
|
||||
[2]=>
|
||||
array(4) {
|
||||
[0]=>
|
||||
int(1)
|
||||
[1]=>
|
||||
int(2)
|
||||
[2]=>
|
||||
int(3)
|
||||
[3]=>
|
||||
int(1)
|
||||
}
|
||||
}
|
||||
-- With more arguments --
|
||||
array(6) {
|
||||
[0]=>
|
||||
array(4) {
|
||||
[0]=>
|
||||
int(1)
|
||||
[1]=>
|
||||
int(2)
|
||||
[2]=>
|
||||
int(3)
|
||||
[3]=>
|
||||
int(1)
|
||||
}
|
||||
["array"]=>
|
||||
array(6) {
|
||||
[0]=>
|
||||
string(5) "hello"
|
||||
[1]=>
|
||||
string(5) "world"
|
||||
["str1"]=>
|
||||
string(5) "hello"
|
||||
["str2"]=>
|
||||
string(5) "world"
|
||||
[2]=>
|
||||
string(5) "hello"
|
||||
[3]=>
|
||||
string(5) "world"
|
||||
}
|
||||
[1]=>
|
||||
array(4) {
|
||||
[1]=>
|
||||
string(3) "one"
|
||||
[2]=>
|
||||
string(3) "two"
|
||||
[3]=>
|
||||
string(3) "one"
|
||||
[4]=>
|
||||
string(3) "two"
|
||||
}
|
||||
[2]=>
|
||||
array(4) {
|
||||
[0]=>
|
||||
int(1)
|
||||
[1]=>
|
||||
int(2)
|
||||
[2]=>
|
||||
int(3)
|
||||
[3]=>
|
||||
int(1)
|
||||
}
|
||||
[3]=>
|
||||
int(1)
|
||||
[4]=>
|
||||
string(5) "hello"
|
||||
}
|
||||
-- Passing the sub-array --
|
||||
-- With default argument --
|
||||
array(4) {
|
||||
[0]=>
|
||||
string(5) "hello"
|
||||
[1]=>
|
||||
string(5) "world"
|
||||
["str1"]=>
|
||||
string(5) "hello"
|
||||
["str2"]=>
|
||||
string(5) "world"
|
||||
}
|
||||
-- With more arguments --
|
||||
array(6) {
|
||||
[0]=>
|
||||
string(5) "hello"
|
||||
[1]=>
|
||||
string(5) "world"
|
||||
["str1"]=>
|
||||
string(5) "hello"
|
||||
["str2"]=>
|
||||
string(5) "world"
|
||||
[2]=>
|
||||
string(5) "hello"
|
||||
[3]=>
|
||||
string(5) "world"
|
||||
}
|
||||
Done
|
199
ext/standard/tests/array/array_merge_recursive_variation2.phpt
Normal file
199
ext/standard/tests/array/array_merge_recursive_variation2.phpt
Normal file
@ -0,0 +1,199 @@
|
||||
--TEST--
|
||||
Test array_merge_recursive() function : usage variations - unexpected values for $arr2 argument
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : array array_merge_recursive(array $arr1[, array $...])
|
||||
* Description: Recursively merges elements from passed arrays into one array
|
||||
* Source code: ext/standard/array.c
|
||||
*/
|
||||
|
||||
/*
|
||||
* Passing non array values to 'arr2' argument of array_merge_recursive() and see
|
||||
* that the function outputs proper warning messages wherever expected.
|
||||
*/
|
||||
|
||||
echo "*** Testing array_merge_recursive() : Passing non array values to \$arr2 argument ***\n";
|
||||
|
||||
// initialise the first argument
|
||||
$arr1 = array(1, array("hello", 'world'));
|
||||
|
||||
//get an unset variable
|
||||
$unset_var = 10;
|
||||
unset($unset_var);
|
||||
|
||||
class A
|
||||
{
|
||||
// public $var = 10;
|
||||
public function __toString() {
|
||||
return "object";
|
||||
}
|
||||
}
|
||||
|
||||
// heredoc string
|
||||
$heredoc = <<<EOT
|
||||
hello world
|
||||
EOT;
|
||||
|
||||
// get a resource variable
|
||||
$fp = fopen(__FILE__, "r");
|
||||
|
||||
// unexpected values to be passed to $arr2 argument
|
||||
$arrays = array (
|
||||
|
||||
// int data
|
||||
/*1*/ 0,
|
||||
1,
|
||||
12345,
|
||||
-2345,
|
||||
|
||||
// float data
|
||||
/*5*/ 10.5,
|
||||
-10.5,
|
||||
12.3456789000e10,
|
||||
12.3456789000E-10,
|
||||
.5,
|
||||
|
||||
// null data
|
||||
/*10*/ NULL,
|
||||
null,
|
||||
|
||||
// boolean data
|
||||
/*12*/ true,
|
||||
false,
|
||||
TRUE,
|
||||
FALSE,
|
||||
|
||||
// empty data
|
||||
/*16*/ "",
|
||||
'',
|
||||
|
||||
// string data
|
||||
/*18*/ "string",
|
||||
'string',
|
||||
$heredoc,
|
||||
|
||||
// undefined data
|
||||
/*21*/ @$undefined_var,
|
||||
|
||||
// unset data
|
||||
/*22*/ @$unset_var,
|
||||
|
||||
// resource variable
|
||||
/*23*/ $fp,
|
||||
|
||||
// object data
|
||||
/*24*/ new A()
|
||||
);
|
||||
|
||||
// loop through each element of $arrays and check the behavior of array_merge_recursive()
|
||||
$iterator = 1;
|
||||
foreach($arrays as $arr2) {
|
||||
echo "\n-- Iteration $iterator --";
|
||||
var_dump( array_merge_recursive($arr1, $arr2) );
|
||||
$iterator++;
|
||||
}
|
||||
|
||||
// close the file resource used
|
||||
fclose($fp);
|
||||
|
||||
echo "Done";
|
||||
?>
|
||||
--EXPECTF--
|
||||
*** Testing array_merge_recursive() : Passing non array values to $arr2 argument ***
|
||||
|
||||
-- Iteration 1 --
|
||||
Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
-- Iteration 2 --
|
||||
Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
-- Iteration 3 --
|
||||
Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
-- Iteration 4 --
|
||||
Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
-- Iteration 5 --
|
||||
Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
-- Iteration 6 --
|
||||
Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
-- Iteration 7 --
|
||||
Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
-- Iteration 8 --
|
||||
Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
-- Iteration 9 --
|
||||
Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
-- Iteration 10 --
|
||||
Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
-- Iteration 11 --
|
||||
Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
-- Iteration 12 --
|
||||
Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
-- Iteration 13 --
|
||||
Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
-- Iteration 14 --
|
||||
Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
-- Iteration 15 --
|
||||
Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
-- Iteration 16 --
|
||||
Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
-- Iteration 17 --
|
||||
Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
-- Iteration 18 --
|
||||
Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
-- Iteration 19 --
|
||||
Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
-- Iteration 20 --
|
||||
Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
-- Iteration 21 --
|
||||
Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
-- Iteration 22 --
|
||||
Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
-- Iteration 23 --
|
||||
Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
-- Iteration 24 --
|
||||
Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
Done
|
765
ext/standard/tests/array/array_merge_recursive_variation3.phpt
Normal file
765
ext/standard/tests/array/array_merge_recursive_variation3.phpt
Normal file
@ -0,0 +1,765 @@
|
||||
--TEST--
|
||||
Test array_merge_recursive() function : usage variations - different arrays for 'arr1' argument
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : array array_merge_recursive(array $arr1[, array $...])
|
||||
* Description: Recursively merges elements from passed arrays into one array
|
||||
* Source code: ext/standard/array.c
|
||||
*/
|
||||
|
||||
/*
|
||||
* Passing different arrays to $arr1 argument and testing whether
|
||||
* array_merge_recursive() behaves in an expected way.
|
||||
*/
|
||||
|
||||
echo "*** Testing array_merge_recursive() : Passing different arrays to \$arr1 argument ***\n";
|
||||
|
||||
/* Different heredoc strings */
|
||||
|
||||
// heredoc with blank line
|
||||
$blank_line = <<<EOT
|
||||
|
||||
|
||||
EOT;
|
||||
|
||||
// heredoc with multiline string
|
||||
$multiline_string = <<<EOT
|
||||
hello world
|
||||
The quick brown fox jumped over;
|
||||
the lazy dog
|
||||
This is a double quoted string
|
||||
EOT;
|
||||
|
||||
// heredoc with diferent whitespaces
|
||||
$diff_whitespaces = <<<EOT
|
||||
hello\r world\t
|
||||
1111\t\t != 2222\v\v
|
||||
heredoc\ndouble quoted string. with\vdifferent\fwhite\vspaces
|
||||
EOT;
|
||||
|
||||
// heredoc with quoted strings and numeric values
|
||||
$numeric_string = <<<EOT
|
||||
11 < 12. 123 >22
|
||||
'single quoted string'
|
||||
"double quoted string"
|
||||
2222 != 1111.\t 0000 = 0000\n
|
||||
EOT;
|
||||
|
||||
// arrays passed to $arr1 argument
|
||||
$arrays = array (
|
||||
/*1*/ array(1, 2,), // with default keys and numeric values
|
||||
array(1.1, 2.2), // with default keys & float values
|
||||
array(false, true), // with default keys and boolean values
|
||||
array(), // empty array
|
||||
/*5*/ array(NULL), // with NULL
|
||||
array("a\v\f", "aaaa\r", "b", "\[\]\!\@\#\$\%\^\&\*\(\)\{\}"), // with double quoted strings
|
||||
array('a\v\f', 'aaaa\r', 'b', '\[\]\!\@\#\$\%\^\&\*\(\)\{\}'), // with single quoted strings
|
||||
array("h1" => $blank_line, "h2" => $multiline_string, "h3" => $diff_whitespaces), // with heredocs
|
||||
|
||||
// associative arrays
|
||||
/*9*/ array(1 => "one", 2 => "two"), // explicit numeric keys, string values
|
||||
array("one" => 1, "two" => 2, "1" => 1 ), // string keys & numeric values
|
||||
array( 1 => 10, 2 => 20, 4 => 40), // explicit numeric keys and numeric values
|
||||
array( "one" => "ten", "two" => "twenty"), // string key/value
|
||||
array("one" => 1, 2 => "two", 4 => "four"), //mixed
|
||||
|
||||
// associative array, containing null/empty/boolean values as key/value
|
||||
/*14*/ array(NULL => "NULL", null => "null", "NULL" => NULL, "null" => null),
|
||||
array(true => "true", false => "false", "false" => false, "true" => true),
|
||||
array("" => "emptyd", '' => 'emptys', "emptyd" => "", 'emptys' => ''),
|
||||
array(1 => '', 2 => "", 3 => NULL, 4 => null, 5 => false, 6 => true),
|
||||
array('' => 1, "" => 2, NULL => 3, null => 4, false => 5, true => 6),
|
||||
|
||||
// array containing embedded arrays
|
||||
/*15*/ array("str1", "array" => array("hello", 'world'), array(1, 2))
|
||||
);
|
||||
|
||||
// initialise the second argument
|
||||
$arr2 = array( 1 => "one", 2, "string" => "hello", "array" => array("a", "b", "c"));
|
||||
|
||||
// loop through each sub array of $arrays and check the behavior of array_merge_recursive()
|
||||
$iterator = 1;
|
||||
foreach($arrays as $arr1) {
|
||||
echo "-- Iteration $iterator --\n";
|
||||
|
||||
// with default argument
|
||||
echo "-- With default argument --\n";
|
||||
var_dump( array_merge_recursive($arr1) );
|
||||
|
||||
// with more arguments
|
||||
echo "-- With more arguments --\n";
|
||||
var_dump( array_merge_recursive($arr1, $arr2) );
|
||||
|
||||
$iterator++;
|
||||
}
|
||||
|
||||
echo "Done";
|
||||
?>
|
||||
--EXPECTF--
|
||||
*** Testing array_merge_recursive() : Passing different arrays to $arr1 argument ***
|
||||
-- Iteration 1 --
|
||||
-- With default argument --
|
||||
array(2) {
|
||||
[0]=>
|
||||
int(1)
|
||||
[1]=>
|
||||
int(2)
|
||||
}
|
||||
-- With more arguments --
|
||||
array(6) {
|
||||
[0]=>
|
||||
int(1)
|
||||
[1]=>
|
||||
int(2)
|
||||
[2]=>
|
||||
string(3) "one"
|
||||
[3]=>
|
||||
int(2)
|
||||
["string"]=>
|
||||
string(5) "hello"
|
||||
["array"]=>
|
||||
array(3) {
|
||||
[0]=>
|
||||
string(1) "a"
|
||||
[1]=>
|
||||
string(1) "b"
|
||||
[2]=>
|
||||
string(1) "c"
|
||||
}
|
||||
}
|
||||
-- Iteration 2 --
|
||||
-- With default argument --
|
||||
array(2) {
|
||||
[0]=>
|
||||
float(1.1)
|
||||
[1]=>
|
||||
float(2.2)
|
||||
}
|
||||
-- With more arguments --
|
||||
array(6) {
|
||||
[0]=>
|
||||
float(1.1)
|
||||
[1]=>
|
||||
float(2.2)
|
||||
[2]=>
|
||||
string(3) "one"
|
||||
[3]=>
|
||||
int(2)
|
||||
["string"]=>
|
||||
string(5) "hello"
|
||||
["array"]=>
|
||||
array(3) {
|
||||
[0]=>
|
||||
string(1) "a"
|
||||
[1]=>
|
||||
string(1) "b"
|
||||
[2]=>
|
||||
string(1) "c"
|
||||
}
|
||||
}
|
||||
-- Iteration 3 --
|
||||
-- With default argument --
|
||||
array(2) {
|
||||
[0]=>
|
||||
bool(false)
|
||||
[1]=>
|
||||
bool(true)
|
||||
}
|
||||
-- With more arguments --
|
||||
array(6) {
|
||||
[0]=>
|
||||
bool(false)
|
||||
[1]=>
|
||||
bool(true)
|
||||
[2]=>
|
||||
string(3) "one"
|
||||
[3]=>
|
||||
int(2)
|
||||
["string"]=>
|
||||
string(5) "hello"
|
||||
["array"]=>
|
||||
array(3) {
|
||||
[0]=>
|
||||
string(1) "a"
|
||||
[1]=>
|
||||
string(1) "b"
|
||||
[2]=>
|
||||
string(1) "c"
|
||||
}
|
||||
}
|
||||
-- Iteration 4 --
|
||||
-- With default argument --
|
||||
array(0) {
|
||||
}
|
||||
-- With more arguments --
|
||||
array(4) {
|
||||
[0]=>
|
||||
string(3) "one"
|
||||
[1]=>
|
||||
int(2)
|
||||
["string"]=>
|
||||
string(5) "hello"
|
||||
["array"]=>
|
||||
array(3) {
|
||||
[0]=>
|
||||
string(1) "a"
|
||||
[1]=>
|
||||
string(1) "b"
|
||||
[2]=>
|
||||
string(1) "c"
|
||||
}
|
||||
}
|
||||
-- Iteration 5 --
|
||||
-- With default argument --
|
||||
array(1) {
|
||||
[0]=>
|
||||
NULL
|
||||
}
|
||||
-- With more arguments --
|
||||
array(5) {
|
||||
[0]=>
|
||||
NULL
|
||||
[1]=>
|
||||
string(3) "one"
|
||||
[2]=>
|
||||
int(2)
|
||||
["string"]=>
|
||||
string(5) "hello"
|
||||
["array"]=>
|
||||
array(3) {
|
||||
[0]=>
|
||||
string(1) "a"
|
||||
[1]=>
|
||||
string(1) "b"
|
||||
[2]=>
|
||||
string(1) "c"
|
||||
}
|
||||
}
|
||||
-- Iteration 6 --
|
||||
-- With default argument --
|
||||
array(4) {
|
||||
[0]=>
|
||||
string(3) "a"
|
||||
[1]=>
|
||||
string(5) "aaaa
|
||||
"
|
||||
[2]=>
|
||||
string(1) "b"
|
||||
[3]=>
|
||||
string(27) "\[\]\!\@\#$\%\^\&\*\(\)\{\}"
|
||||
}
|
||||
-- With more arguments --
|
||||
array(8) {
|
||||
[0]=>
|
||||
string(3) "a"
|
||||
[1]=>
|
||||
string(5) "aaaa
|
||||
"
|
||||
[2]=>
|
||||
string(1) "b"
|
||||
[3]=>
|
||||
string(27) "\[\]\!\@\#$\%\^\&\*\(\)\{\}"
|
||||
[4]=>
|
||||
string(3) "one"
|
||||
[5]=>
|
||||
int(2)
|
||||
["string"]=>
|
||||
string(5) "hello"
|
||||
["array"]=>
|
||||
array(3) {
|
||||
[0]=>
|
||||
string(1) "a"
|
||||
[1]=>
|
||||
string(1) "b"
|
||||
[2]=>
|
||||
string(1) "c"
|
||||
}
|
||||
}
|
||||
-- Iteration 7 --
|
||||
-- With default argument --
|
||||
array(4) {
|
||||
[0]=>
|
||||
string(5) "a\v\f"
|
||||
[1]=>
|
||||
string(6) "aaaa\r"
|
||||
[2]=>
|
||||
string(1) "b"
|
||||
[3]=>
|
||||
string(28) "\[\]\!\@\#\$\%\^\&\*\(\)\{\}"
|
||||
}
|
||||
-- With more arguments --
|
||||
array(8) {
|
||||
[0]=>
|
||||
string(5) "a\v\f"
|
||||
[1]=>
|
||||
string(6) "aaaa\r"
|
||||
[2]=>
|
||||
string(1) "b"
|
||||
[3]=>
|
||||
string(28) "\[\]\!\@\#\$\%\^\&\*\(\)\{\}"
|
||||
[4]=>
|
||||
string(3) "one"
|
||||
[5]=>
|
||||
int(2)
|
||||
["string"]=>
|
||||
string(5) "hello"
|
||||
["array"]=>
|
||||
array(3) {
|
||||
[0]=>
|
||||
string(1) "a"
|
||||
[1]=>
|
||||
string(1) "b"
|
||||
[2]=>
|
||||
string(1) "c"
|
||||
}
|
||||
}
|
||||
-- Iteration 8 --
|
||||
-- With default argument --
|
||||
array(3) {
|
||||
["h1"]=>
|
||||
string(1) "
|
||||
"
|
||||
["h2"]=>
|
||||
string(88) "hello world
|
||||
The quick brown fox jumped over;
|
||||
the lazy dog
|
||||
This is a double quoted string"
|
||||
["h3"]=>
|
||||
string(88) "hello
|
||||
world
|
||||
1111 != 2222
|
||||
heredoc
|
||||
double quoted string. withdifferentwhitespaces"
|
||||
}
|
||||
-- With more arguments --
|
||||
array(7) {
|
||||
["h1"]=>
|
||||
string(1) "
|
||||
"
|
||||
["h2"]=>
|
||||
string(88) "hello world
|
||||
The quick brown fox jumped over;
|
||||
the lazy dog
|
||||
This is a double quoted string"
|
||||
["h3"]=>
|
||||
string(88) "hello
|
||||
world
|
||||
1111 != 2222
|
||||
heredoc
|
||||
double quoted string. withdifferentwhitespaces"
|
||||
[0]=>
|
||||
string(3) "one"
|
||||
[1]=>
|
||||
int(2)
|
||||
["string"]=>
|
||||
string(5) "hello"
|
||||
["array"]=>
|
||||
array(3) {
|
||||
[0]=>
|
||||
string(1) "a"
|
||||
[1]=>
|
||||
string(1) "b"
|
||||
[2]=>
|
||||
string(1) "c"
|
||||
}
|
||||
}
|
||||
-- Iteration 9 --
|
||||
-- With default argument --
|
||||
array(2) {
|
||||
[0]=>
|
||||
string(3) "one"
|
||||
[1]=>
|
||||
string(3) "two"
|
||||
}
|
||||
-- With more arguments --
|
||||
array(6) {
|
||||
[0]=>
|
||||
string(3) "one"
|
||||
[1]=>
|
||||
string(3) "two"
|
||||
[2]=>
|
||||
string(3) "one"
|
||||
[3]=>
|
||||
int(2)
|
||||
["string"]=>
|
||||
string(5) "hello"
|
||||
["array"]=>
|
||||
array(3) {
|
||||
[0]=>
|
||||
string(1) "a"
|
||||
[1]=>
|
||||
string(1) "b"
|
||||
[2]=>
|
||||
string(1) "c"
|
||||
}
|
||||
}
|
||||
-- Iteration 10 --
|
||||
-- With default argument --
|
||||
array(3) {
|
||||
["one"]=>
|
||||
int(1)
|
||||
["two"]=>
|
||||
int(2)
|
||||
[0]=>
|
||||
int(1)
|
||||
}
|
||||
-- With more arguments --
|
||||
array(7) {
|
||||
["one"]=>
|
||||
int(1)
|
||||
["two"]=>
|
||||
int(2)
|
||||
[0]=>
|
||||
int(1)
|
||||
[1]=>
|
||||
string(3) "one"
|
||||
[2]=>
|
||||
int(2)
|
||||
["string"]=>
|
||||
string(5) "hello"
|
||||
["array"]=>
|
||||
array(3) {
|
||||
[0]=>
|
||||
string(1) "a"
|
||||
[1]=>
|
||||
string(1) "b"
|
||||
[2]=>
|
||||
string(1) "c"
|
||||
}
|
||||
}
|
||||
-- Iteration 11 --
|
||||
-- With default argument --
|
||||
array(3) {
|
||||
[0]=>
|
||||
int(10)
|
||||
[1]=>
|
||||
int(20)
|
||||
[2]=>
|
||||
int(40)
|
||||
}
|
||||
-- With more arguments --
|
||||
array(7) {
|
||||
[0]=>
|
||||
int(10)
|
||||
[1]=>
|
||||
int(20)
|
||||
[2]=>
|
||||
int(40)
|
||||
[3]=>
|
||||
string(3) "one"
|
||||
[4]=>
|
||||
int(2)
|
||||
["string"]=>
|
||||
string(5) "hello"
|
||||
["array"]=>
|
||||
array(3) {
|
||||
[0]=>
|
||||
string(1) "a"
|
||||
[1]=>
|
||||
string(1) "b"
|
||||
[2]=>
|
||||
string(1) "c"
|
||||
}
|
||||
}
|
||||
-- Iteration 12 --
|
||||
-- With default argument --
|
||||
array(2) {
|
||||
["one"]=>
|
||||
string(3) "ten"
|
||||
["two"]=>
|
||||
string(6) "twenty"
|
||||
}
|
||||
-- With more arguments --
|
||||
array(6) {
|
||||
["one"]=>
|
||||
string(3) "ten"
|
||||
["two"]=>
|
||||
string(6) "twenty"
|
||||
[0]=>
|
||||
string(3) "one"
|
||||
[1]=>
|
||||
int(2)
|
||||
["string"]=>
|
||||
string(5) "hello"
|
||||
["array"]=>
|
||||
array(3) {
|
||||
[0]=>
|
||||
string(1) "a"
|
||||
[1]=>
|
||||
string(1) "b"
|
||||
[2]=>
|
||||
string(1) "c"
|
||||
}
|
||||
}
|
||||
-- Iteration 13 --
|
||||
-- With default argument --
|
||||
array(3) {
|
||||
["one"]=>
|
||||
int(1)
|
||||
[0]=>
|
||||
string(3) "two"
|
||||
[1]=>
|
||||
string(4) "four"
|
||||
}
|
||||
-- With more arguments --
|
||||
array(7) {
|
||||
["one"]=>
|
||||
int(1)
|
||||
[0]=>
|
||||
string(3) "two"
|
||||
[1]=>
|
||||
string(4) "four"
|
||||
[2]=>
|
||||
string(3) "one"
|
||||
[3]=>
|
||||
int(2)
|
||||
["string"]=>
|
||||
string(5) "hello"
|
||||
["array"]=>
|
||||
array(3) {
|
||||
[0]=>
|
||||
string(1) "a"
|
||||
[1]=>
|
||||
string(1) "b"
|
||||
[2]=>
|
||||
string(1) "c"
|
||||
}
|
||||
}
|
||||
-- Iteration 14 --
|
||||
-- With default argument --
|
||||
array(3) {
|
||||
[""]=>
|
||||
string(4) "null"
|
||||
["NULL"]=>
|
||||
NULL
|
||||
["null"]=>
|
||||
NULL
|
||||
}
|
||||
-- With more arguments --
|
||||
array(7) {
|
||||
[""]=>
|
||||
string(4) "null"
|
||||
["NULL"]=>
|
||||
NULL
|
||||
["null"]=>
|
||||
NULL
|
||||
[0]=>
|
||||
string(3) "one"
|
||||
[1]=>
|
||||
int(2)
|
||||
["string"]=>
|
||||
string(5) "hello"
|
||||
["array"]=>
|
||||
array(3) {
|
||||
[0]=>
|
||||
string(1) "a"
|
||||
[1]=>
|
||||
string(1) "b"
|
||||
[2]=>
|
||||
string(1) "c"
|
||||
}
|
||||
}
|
||||
-- Iteration 15 --
|
||||
-- With default argument --
|
||||
array(4) {
|
||||
[0]=>
|
||||
string(4) "true"
|
||||
[1]=>
|
||||
string(5) "false"
|
||||
["false"]=>
|
||||
bool(false)
|
||||
["true"]=>
|
||||
bool(true)
|
||||
}
|
||||
-- With more arguments --
|
||||
array(8) {
|
||||
[0]=>
|
||||
string(4) "true"
|
||||
[1]=>
|
||||
string(5) "false"
|
||||
["false"]=>
|
||||
bool(false)
|
||||
["true"]=>
|
||||
bool(true)
|
||||
[2]=>
|
||||
string(3) "one"
|
||||
[3]=>
|
||||
int(2)
|
||||
["string"]=>
|
||||
string(5) "hello"
|
||||
["array"]=>
|
||||
array(3) {
|
||||
[0]=>
|
||||
string(1) "a"
|
||||
[1]=>
|
||||
string(1) "b"
|
||||
[2]=>
|
||||
string(1) "c"
|
||||
}
|
||||
}
|
||||
-- Iteration 16 --
|
||||
-- With default argument --
|
||||
array(3) {
|
||||
[""]=>
|
||||
string(6) "emptys"
|
||||
["emptyd"]=>
|
||||
string(0) ""
|
||||
["emptys"]=>
|
||||
string(0) ""
|
||||
}
|
||||
-- With more arguments --
|
||||
array(7) {
|
||||
[""]=>
|
||||
string(6) "emptys"
|
||||
["emptyd"]=>
|
||||
string(0) ""
|
||||
["emptys"]=>
|
||||
string(0) ""
|
||||
[0]=>
|
||||
string(3) "one"
|
||||
[1]=>
|
||||
int(2)
|
||||
["string"]=>
|
||||
string(5) "hello"
|
||||
["array"]=>
|
||||
array(3) {
|
||||
[0]=>
|
||||
string(1) "a"
|
||||
[1]=>
|
||||
string(1) "b"
|
||||
[2]=>
|
||||
string(1) "c"
|
||||
}
|
||||
}
|
||||
-- Iteration 17 --
|
||||
-- With default argument --
|
||||
array(6) {
|
||||
[0]=>
|
||||
string(0) ""
|
||||
[1]=>
|
||||
string(0) ""
|
||||
[2]=>
|
||||
NULL
|
||||
[3]=>
|
||||
NULL
|
||||
[4]=>
|
||||
bool(false)
|
||||
[5]=>
|
||||
bool(true)
|
||||
}
|
||||
-- With more arguments --
|
||||
array(10) {
|
||||
[0]=>
|
||||
string(0) ""
|
||||
[1]=>
|
||||
string(0) ""
|
||||
[2]=>
|
||||
NULL
|
||||
[3]=>
|
||||
NULL
|
||||
[4]=>
|
||||
bool(false)
|
||||
[5]=>
|
||||
bool(true)
|
||||
[6]=>
|
||||
string(3) "one"
|
||||
[7]=>
|
||||
int(2)
|
||||
["string"]=>
|
||||
string(5) "hello"
|
||||
["array"]=>
|
||||
array(3) {
|
||||
[0]=>
|
||||
string(1) "a"
|
||||
[1]=>
|
||||
string(1) "b"
|
||||
[2]=>
|
||||
string(1) "c"
|
||||
}
|
||||
}
|
||||
-- Iteration 18 --
|
||||
-- With default argument --
|
||||
array(3) {
|
||||
[""]=>
|
||||
int(4)
|
||||
[0]=>
|
||||
int(5)
|
||||
[1]=>
|
||||
int(6)
|
||||
}
|
||||
-- With more arguments --
|
||||
array(7) {
|
||||
[""]=>
|
||||
int(4)
|
||||
[0]=>
|
||||
int(5)
|
||||
[1]=>
|
||||
int(6)
|
||||
[2]=>
|
||||
string(3) "one"
|
||||
[3]=>
|
||||
int(2)
|
||||
["string"]=>
|
||||
string(5) "hello"
|
||||
["array"]=>
|
||||
array(3) {
|
||||
[0]=>
|
||||
string(1) "a"
|
||||
[1]=>
|
||||
string(1) "b"
|
||||
[2]=>
|
||||
string(1) "c"
|
||||
}
|
||||
}
|
||||
-- Iteration 19 --
|
||||
-- With default argument --
|
||||
array(3) {
|
||||
[0]=>
|
||||
string(4) "str1"
|
||||
["array"]=>
|
||||
array(2) {
|
||||
[0]=>
|
||||
string(5) "hello"
|
||||
[1]=>
|
||||
string(5) "world"
|
||||
}
|
||||
[1]=>
|
||||
array(2) {
|
||||
[0]=>
|
||||
int(1)
|
||||
[1]=>
|
||||
int(2)
|
||||
}
|
||||
}
|
||||
-- With more arguments --
|
||||
array(6) {
|
||||
[0]=>
|
||||
string(4) "str1"
|
||||
["array"]=>
|
||||
array(5) {
|
||||
[0]=>
|
||||
string(5) "hello"
|
||||
[1]=>
|
||||
string(5) "world"
|
||||
[2]=>
|
||||
string(1) "a"
|
||||
[3]=>
|
||||
string(1) "b"
|
||||
[4]=>
|
||||
string(1) "c"
|
||||
}
|
||||
[1]=>
|
||||
array(2) {
|
||||
[0]=>
|
||||
int(1)
|
||||
[1]=>
|
||||
int(2)
|
||||
}
|
||||
[2]=>
|
||||
string(3) "one"
|
||||
[3]=>
|
||||
int(2)
|
||||
["string"]=>
|
||||
string(5) "hello"
|
||||
}
|
||||
Done
|
424
ext/standard/tests/array/array_merge_recursive_variation4.phpt
Normal file
424
ext/standard/tests/array/array_merge_recursive_variation4.phpt
Normal file
@ -0,0 +1,424 @@
|
||||
--TEST--
|
||||
Test array_merge_recursive() function : usage variations - associative array with different keys
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : array array_merge_recursive(array $arr1[, array $...])
|
||||
* Description: Recursively merges elements from passed arrays into one array
|
||||
* Source code: ext/standard/array.c
|
||||
*/
|
||||
|
||||
/*
|
||||
* Testing the functionality of array_merge_recursive() by passing different
|
||||
* associative arrays having different keys to $arr1 argument.
|
||||
*/
|
||||
|
||||
echo "*** Testing array_merge_recursive() : assoc. array with diff. keys to \$arr1 argument ***\n";
|
||||
|
||||
// get an unset variable
|
||||
$unset_var = 10;
|
||||
unset ($unset_var);
|
||||
|
||||
// get a resource variable
|
||||
$fp = fopen(__FILE__, "r");
|
||||
|
||||
// get a class
|
||||
class classA
|
||||
{
|
||||
public function __toString(){
|
||||
return "Class A object";
|
||||
}
|
||||
}
|
||||
|
||||
// get a heredoc string
|
||||
$heredoc = <<<EOT
|
||||
Hello world
|
||||
EOT;
|
||||
|
||||
// different associative arrays to be passed to $arr1 argument
|
||||
$arrays = array (
|
||||
/*1*/ // arrays with integer keys
|
||||
array(0 => "0", 1 => array(1 => "one")),
|
||||
array(1 => "1", 2 => array(1 => "one", 2 => "two", 3 => 1, 4 => "4")),
|
||||
|
||||
// arrays with float keys
|
||||
/*3*/ array(2.3333 => "float", 44.44 => array(1.1 => "float")),
|
||||
array(1.2 => "f1", 3.33 => "f2", 4.89999922839999 => array(1.1 => "f1"), 3333333.333333 => "f4"),
|
||||
|
||||
// arrays with string keys
|
||||
/*5*/ array('\tHello' => array("hello", 'world'), '\v\fworld' => 2.2, 'pen\n' => 111),
|
||||
array("\tHello" => array("hello", 'world'), "\v\fworld" => 2.2, "pen\n" => 111),
|
||||
array("hello", $heredoc => array("heredoc", 'string'), "string"),
|
||||
|
||||
// array with object, unset variable and resource variable
|
||||
/*8*/ array(new classA() => 11, @$unset_var => array("unset"), $fp => 'resource', 11, "hello")
|
||||
);
|
||||
|
||||
// initialise the second array
|
||||
$arr2 = array( 1 => "one", 2, "string" => "hello", "array" => array("a", "b", "c"));
|
||||
|
||||
// loop through each sub array of $arrays and check the behavior of array_merge_recursive()
|
||||
$iterator = 1;
|
||||
foreach($arrays as $arr1) {
|
||||
echo "-- Iteration $iterator --\n";
|
||||
|
||||
// with default argument
|
||||
echo "-- With default argument --\n";
|
||||
var_dump( array_merge_recursive($arr1) );
|
||||
|
||||
// with more arguments
|
||||
echo "-- With more arguments --\n";
|
||||
var_dump( array_merge_recursive($arr1, $arr2) );
|
||||
|
||||
$iterator++;
|
||||
}
|
||||
|
||||
// close the file resource used
|
||||
fclose($fp);
|
||||
|
||||
echo "Done";
|
||||
?>
|
||||
--EXPECTF--
|
||||
*** Testing array_merge_recursive() : assoc. array with diff. keys to $arr1 argument ***
|
||||
|
||||
Warning: Illegal offset type in %s on line %d
|
||||
|
||||
Warning: Illegal offset type in %s on line %d
|
||||
-- Iteration 1 --
|
||||
-- With default argument --
|
||||
array(2) {
|
||||
[0]=>
|
||||
string(1) "0"
|
||||
[1]=>
|
||||
array(1) {
|
||||
[1]=>
|
||||
string(3) "one"
|
||||
}
|
||||
}
|
||||
-- With more arguments --
|
||||
array(6) {
|
||||
[0]=>
|
||||
string(1) "0"
|
||||
[1]=>
|
||||
array(1) {
|
||||
[1]=>
|
||||
string(3) "one"
|
||||
}
|
||||
[2]=>
|
||||
string(3) "one"
|
||||
[3]=>
|
||||
int(2)
|
||||
["string"]=>
|
||||
string(5) "hello"
|
||||
["array"]=>
|
||||
array(3) {
|
||||
[0]=>
|
||||
string(1) "a"
|
||||
[1]=>
|
||||
string(1) "b"
|
||||
[2]=>
|
||||
string(1) "c"
|
||||
}
|
||||
}
|
||||
-- Iteration 2 --
|
||||
-- With default argument --
|
||||
array(2) {
|
||||
[0]=>
|
||||
string(1) "1"
|
||||
[1]=>
|
||||
array(4) {
|
||||
[1]=>
|
||||
string(3) "one"
|
||||
[2]=>
|
||||
string(3) "two"
|
||||
[3]=>
|
||||
int(1)
|
||||
[4]=>
|
||||
string(1) "4"
|
||||
}
|
||||
}
|
||||
-- With more arguments --
|
||||
array(6) {
|
||||
[0]=>
|
||||
string(1) "1"
|
||||
[1]=>
|
||||
array(4) {
|
||||
[1]=>
|
||||
string(3) "one"
|
||||
[2]=>
|
||||
string(3) "two"
|
||||
[3]=>
|
||||
int(1)
|
||||
[4]=>
|
||||
string(1) "4"
|
||||
}
|
||||
[2]=>
|
||||
string(3) "one"
|
||||
[3]=>
|
||||
int(2)
|
||||
["string"]=>
|
||||
string(5) "hello"
|
||||
["array"]=>
|
||||
array(3) {
|
||||
[0]=>
|
||||
string(1) "a"
|
||||
[1]=>
|
||||
string(1) "b"
|
||||
[2]=>
|
||||
string(1) "c"
|
||||
}
|
||||
}
|
||||
-- Iteration 3 --
|
||||
-- With default argument --
|
||||
array(2) {
|
||||
[0]=>
|
||||
string(5) "float"
|
||||
[1]=>
|
||||
array(1) {
|
||||
[1]=>
|
||||
string(5) "float"
|
||||
}
|
||||
}
|
||||
-- With more arguments --
|
||||
array(6) {
|
||||
[0]=>
|
||||
string(5) "float"
|
||||
[1]=>
|
||||
array(1) {
|
||||
[1]=>
|
||||
string(5) "float"
|
||||
}
|
||||
[2]=>
|
||||
string(3) "one"
|
||||
[3]=>
|
||||
int(2)
|
||||
["string"]=>
|
||||
string(5) "hello"
|
||||
["array"]=>
|
||||
array(3) {
|
||||
[0]=>
|
||||
string(1) "a"
|
||||
[1]=>
|
||||
string(1) "b"
|
||||
[2]=>
|
||||
string(1) "c"
|
||||
}
|
||||
}
|
||||
-- Iteration 4 --
|
||||
-- With default argument --
|
||||
array(4) {
|
||||
[0]=>
|
||||
string(2) "f1"
|
||||
[1]=>
|
||||
string(2) "f2"
|
||||
[2]=>
|
||||
array(1) {
|
||||
[1]=>
|
||||
string(2) "f1"
|
||||
}
|
||||
[3]=>
|
||||
string(2) "f4"
|
||||
}
|
||||
-- With more arguments --
|
||||
array(8) {
|
||||
[0]=>
|
||||
string(2) "f1"
|
||||
[1]=>
|
||||
string(2) "f2"
|
||||
[2]=>
|
||||
array(1) {
|
||||
[1]=>
|
||||
string(2) "f1"
|
||||
}
|
||||
[3]=>
|
||||
string(2) "f4"
|
||||
[4]=>
|
||||
string(3) "one"
|
||||
[5]=>
|
||||
int(2)
|
||||
["string"]=>
|
||||
string(5) "hello"
|
||||
["array"]=>
|
||||
array(3) {
|
||||
[0]=>
|
||||
string(1) "a"
|
||||
[1]=>
|
||||
string(1) "b"
|
||||
[2]=>
|
||||
string(1) "c"
|
||||
}
|
||||
}
|
||||
-- Iteration 5 --
|
||||
-- With default argument --
|
||||
array(3) {
|
||||
["\tHello"]=>
|
||||
array(2) {
|
||||
[0]=>
|
||||
string(5) "hello"
|
||||
[1]=>
|
||||
string(5) "world"
|
||||
}
|
||||
["\v\fworld"]=>
|
||||
float(2.2)
|
||||
["pen\n"]=>
|
||||
int(111)
|
||||
}
|
||||
-- With more arguments --
|
||||
array(7) {
|
||||
["\tHello"]=>
|
||||
array(2) {
|
||||
[0]=>
|
||||
string(5) "hello"
|
||||
[1]=>
|
||||
string(5) "world"
|
||||
}
|
||||
["\v\fworld"]=>
|
||||
float(2.2)
|
||||
["pen\n"]=>
|
||||
int(111)
|
||||
[0]=>
|
||||
string(3) "one"
|
||||
[1]=>
|
||||
int(2)
|
||||
["string"]=>
|
||||
string(5) "hello"
|
||||
["array"]=>
|
||||
array(3) {
|
||||
[0]=>
|
||||
string(1) "a"
|
||||
[1]=>
|
||||
string(1) "b"
|
||||
[2]=>
|
||||
string(1) "c"
|
||||
}
|
||||
}
|
||||
-- Iteration 6 --
|
||||
-- With default argument --
|
||||
array(3) {
|
||||
[" Hello"]=>
|
||||
array(2) {
|
||||
[0]=>
|
||||
string(5) "hello"
|
||||
[1]=>
|
||||
string(5) "world"
|
||||
}
|
||||
["world"]=>
|
||||
float(2.2)
|
||||
["pen
|
||||
"]=>
|
||||
int(111)
|
||||
}
|
||||
-- With more arguments --
|
||||
array(7) {
|
||||
[" Hello"]=>
|
||||
array(2) {
|
||||
[0]=>
|
||||
string(5) "hello"
|
||||
[1]=>
|
||||
string(5) "world"
|
||||
}
|
||||
["world"]=>
|
||||
float(2.2)
|
||||
["pen
|
||||
"]=>
|
||||
int(111)
|
||||
[0]=>
|
||||
string(3) "one"
|
||||
[1]=>
|
||||
int(2)
|
||||
["string"]=>
|
||||
string(5) "hello"
|
||||
["array"]=>
|
||||
array(3) {
|
||||
[0]=>
|
||||
string(1) "a"
|
||||
[1]=>
|
||||
string(1) "b"
|
||||
[2]=>
|
||||
string(1) "c"
|
||||
}
|
||||
}
|
||||
-- Iteration 7 --
|
||||
-- With default argument --
|
||||
array(3) {
|
||||
[0]=>
|
||||
string(5) "hello"
|
||||
["Hello world"]=>
|
||||
array(2) {
|
||||
[0]=>
|
||||
string(7) "heredoc"
|
||||
[1]=>
|
||||
string(6) "string"
|
||||
}
|
||||
[1]=>
|
||||
string(6) "string"
|
||||
}
|
||||
-- With more arguments --
|
||||
array(7) {
|
||||
[0]=>
|
||||
string(5) "hello"
|
||||
["Hello world"]=>
|
||||
array(2) {
|
||||
[0]=>
|
||||
string(7) "heredoc"
|
||||
[1]=>
|
||||
string(6) "string"
|
||||
}
|
||||
[1]=>
|
||||
string(6) "string"
|
||||
[2]=>
|
||||
string(3) "one"
|
||||
[3]=>
|
||||
int(2)
|
||||
["string"]=>
|
||||
string(5) "hello"
|
||||
["array"]=>
|
||||
array(3) {
|
||||
[0]=>
|
||||
string(1) "a"
|
||||
[1]=>
|
||||
string(1) "b"
|
||||
[2]=>
|
||||
string(1) "c"
|
||||
}
|
||||
}
|
||||
-- Iteration 8 --
|
||||
-- With default argument --
|
||||
array(3) {
|
||||
[""]=>
|
||||
array(1) {
|
||||
[0]=>
|
||||
string(5) "unset"
|
||||
}
|
||||
[0]=>
|
||||
int(11)
|
||||
[1]=>
|
||||
string(5) "hello"
|
||||
}
|
||||
-- With more arguments --
|
||||
array(7) {
|
||||
[""]=>
|
||||
array(1) {
|
||||
[0]=>
|
||||
string(5) "unset"
|
||||
}
|
||||
[0]=>
|
||||
int(11)
|
||||
[1]=>
|
||||
string(5) "hello"
|
||||
[2]=>
|
||||
string(3) "one"
|
||||
[3]=>
|
||||
int(2)
|
||||
["string"]=>
|
||||
string(5) "hello"
|
||||
["array"]=>
|
||||
array(3) {
|
||||
[0]=>
|
||||
string(1) "a"
|
||||
[1]=>
|
||||
string(1) "b"
|
||||
[2]=>
|
||||
string(1) "c"
|
||||
}
|
||||
}
|
||||
Done
|
402
ext/standard/tests/array/array_merge_recursive_variation5.phpt
Normal file
402
ext/standard/tests/array/array_merge_recursive_variation5.phpt
Normal file
@ -0,0 +1,402 @@
|
||||
--TEST--
|
||||
Test array_merge_recursive() function : usage variations - associative array with different values
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : array array_merge_recursive(array $arr1[, array $...])
|
||||
* Description: Recursively merges elements from passed arrays into one array
|
||||
* Source code: ext/standard/array.c
|
||||
*/
|
||||
|
||||
/*
|
||||
* Testing the functionality of array_merge_recursive() by passing different
|
||||
* associative arrays having different values to $arr1 argument.
|
||||
*/
|
||||
|
||||
echo "*** Testing array_merge_recursive() : assoc. array with diff. values to \$arr1 argument ***\n";
|
||||
|
||||
// get an unset variable
|
||||
$unset_var = 10;
|
||||
unset ($unset_var);
|
||||
|
||||
// get a resource variable
|
||||
$fp = fopen(__FILE__, "r");
|
||||
|
||||
// get a class
|
||||
class classA
|
||||
{
|
||||
public function __toString(){
|
||||
return "Class A object";
|
||||
}
|
||||
}
|
||||
|
||||
// get a heredoc string
|
||||
$heredoc = <<<EOT
|
||||
Hello world
|
||||
EOT;
|
||||
|
||||
// different associative arrays to be passed to $arr1 argument
|
||||
$arrays = array (
|
||||
// arrays with integer values
|
||||
/*1*/ array('0' => 0, '1' => 0),
|
||||
array("one" => 1, 'two' => 2, "three" => 1, 4 => 1),
|
||||
|
||||
// arrays with float values
|
||||
/*3*/ array("f1" => 2.3333, "f2" => 2.3333, "f3" => array(1.1, 2.22)),
|
||||
array("f1" => 1.2, 'f2' => 3.33, 3 => 4.89999922839999, 'f4' => array(1.2, 'f4' => 1.2)),
|
||||
|
||||
// arrays with string values
|
||||
/*5*/ array(111 => "\tHello", "array" => "col\tor", 2 => "\v\fworld", 3.3 => "\tHello"),
|
||||
array(111 => '\tHello', 'array' => 'col\tor', 2 => '\v\fworld', 3.3 => '\tHello'),
|
||||
array(1 => "hello", "string" => $heredoc, $heredoc),
|
||||
|
||||
// array with object, unset variable and resource variable
|
||||
/*8*/ array(11 => new classA(), "string" => @$unset_var, "resource" => $fp, new classA(), $fp),
|
||||
);
|
||||
|
||||
// initialise the second array
|
||||
$arr2 = array( 1 => "one", 2, "string" => "hello", "array" => array("a", "b", "c"));
|
||||
|
||||
// loop through each sub array of $arrays and check the behavior of array_merge_recursive()
|
||||
$iterator = 1;
|
||||
foreach($arrays as $arr1) {
|
||||
echo "-- Iteration $iterator --\n";
|
||||
|
||||
// with default argument
|
||||
echo "-- With default argument --\n";
|
||||
var_dump( array_merge_recursive($arr1) );
|
||||
|
||||
// with more arguments
|
||||
echo "-- With more arguments --\n";
|
||||
var_dump( array_merge_recursive($arr1, $arr2) );
|
||||
|
||||
$iterator++;
|
||||
}
|
||||
|
||||
// close the file resource used
|
||||
fclose($fp);
|
||||
|
||||
echo "Done";
|
||||
?>
|
||||
--EXPECTF--
|
||||
*** Testing array_merge_recursive() : assoc. array with diff. values to $arr1 argument ***
|
||||
-- Iteration 1 --
|
||||
-- With default argument --
|
||||
array(2) {
|
||||
[0]=>
|
||||
int(0)
|
||||
[1]=>
|
||||
int(0)
|
||||
}
|
||||
-- With more arguments --
|
||||
array(6) {
|
||||
[0]=>
|
||||
int(0)
|
||||
[1]=>
|
||||
int(0)
|
||||
[2]=>
|
||||
string(3) "one"
|
||||
[3]=>
|
||||
int(2)
|
||||
["string"]=>
|
||||
string(5) "hello"
|
||||
["array"]=>
|
||||
array(3) {
|
||||
[0]=>
|
||||
string(1) "a"
|
||||
[1]=>
|
||||
string(1) "b"
|
||||
[2]=>
|
||||
string(1) "c"
|
||||
}
|
||||
}
|
||||
-- Iteration 2 --
|
||||
-- With default argument --
|
||||
array(4) {
|
||||
["one"]=>
|
||||
int(1)
|
||||
["two"]=>
|
||||
int(2)
|
||||
["three"]=>
|
||||
int(1)
|
||||
[0]=>
|
||||
int(1)
|
||||
}
|
||||
-- With more arguments --
|
||||
array(8) {
|
||||
["one"]=>
|
||||
int(1)
|
||||
["two"]=>
|
||||
int(2)
|
||||
["three"]=>
|
||||
int(1)
|
||||
[0]=>
|
||||
int(1)
|
||||
[1]=>
|
||||
string(3) "one"
|
||||
[2]=>
|
||||
int(2)
|
||||
["string"]=>
|
||||
string(5) "hello"
|
||||
["array"]=>
|
||||
array(3) {
|
||||
[0]=>
|
||||
string(1) "a"
|
||||
[1]=>
|
||||
string(1) "b"
|
||||
[2]=>
|
||||
string(1) "c"
|
||||
}
|
||||
}
|
||||
-- Iteration 3 --
|
||||
-- With default argument --
|
||||
array(3) {
|
||||
["f1"]=>
|
||||
float(2.3333)
|
||||
["f2"]=>
|
||||
float(2.3333)
|
||||
["f3"]=>
|
||||
array(2) {
|
||||
[0]=>
|
||||
float(1.1)
|
||||
[1]=>
|
||||
float(2.22)
|
||||
}
|
||||
}
|
||||
-- With more arguments --
|
||||
array(7) {
|
||||
["f1"]=>
|
||||
float(2.3333)
|
||||
["f2"]=>
|
||||
float(2.3333)
|
||||
["f3"]=>
|
||||
array(2) {
|
||||
[0]=>
|
||||
float(1.1)
|
||||
[1]=>
|
||||
float(2.22)
|
||||
}
|
||||
[0]=>
|
||||
string(3) "one"
|
||||
[1]=>
|
||||
int(2)
|
||||
["string"]=>
|
||||
string(5) "hello"
|
||||
["array"]=>
|
||||
array(3) {
|
||||
[0]=>
|
||||
string(1) "a"
|
||||
[1]=>
|
||||
string(1) "b"
|
||||
[2]=>
|
||||
string(1) "c"
|
||||
}
|
||||
}
|
||||
-- Iteration 4 --
|
||||
-- With default argument --
|
||||
array(4) {
|
||||
["f1"]=>
|
||||
float(1.2)
|
||||
["f2"]=>
|
||||
float(3.33)
|
||||
[0]=>
|
||||
float(4.8999992284)
|
||||
["f4"]=>
|
||||
array(2) {
|
||||
[0]=>
|
||||
float(1.2)
|
||||
["f4"]=>
|
||||
float(1.2)
|
||||
}
|
||||
}
|
||||
-- With more arguments --
|
||||
array(8) {
|
||||
["f1"]=>
|
||||
float(1.2)
|
||||
["f2"]=>
|
||||
float(3.33)
|
||||
[0]=>
|
||||
float(4.8999992284)
|
||||
["f4"]=>
|
||||
array(2) {
|
||||
[0]=>
|
||||
float(1.2)
|
||||
["f4"]=>
|
||||
float(1.2)
|
||||
}
|
||||
[1]=>
|
||||
string(3) "one"
|
||||
[2]=>
|
||||
int(2)
|
||||
["string"]=>
|
||||
string(5) "hello"
|
||||
["array"]=>
|
||||
array(3) {
|
||||
[0]=>
|
||||
string(1) "a"
|
||||
[1]=>
|
||||
string(1) "b"
|
||||
[2]=>
|
||||
string(1) "c"
|
||||
}
|
||||
}
|
||||
-- Iteration 5 --
|
||||
-- With default argument --
|
||||
array(4) {
|
||||
[0]=>
|
||||
string(6) " Hello"
|
||||
["array"]=>
|
||||
string(6) "col or"
|
||||
[1]=>
|
||||
string(7) "world"
|
||||
[2]=>
|
||||
string(6) " Hello"
|
||||
}
|
||||
-- With more arguments --
|
||||
array(7) {
|
||||
[0]=>
|
||||
string(6) " Hello"
|
||||
["array"]=>
|
||||
array(4) {
|
||||
[0]=>
|
||||
string(6) "col or"
|
||||
[1]=>
|
||||
string(1) "a"
|
||||
[2]=>
|
||||
string(1) "b"
|
||||
[3]=>
|
||||
string(1) "c"
|
||||
}
|
||||
[1]=>
|
||||
string(7) "world"
|
||||
[2]=>
|
||||
string(6) " Hello"
|
||||
[3]=>
|
||||
string(3) "one"
|
||||
[4]=>
|
||||
int(2)
|
||||
["string"]=>
|
||||
string(5) "hello"
|
||||
}
|
||||
-- Iteration 6 --
|
||||
-- With default argument --
|
||||
array(4) {
|
||||
[0]=>
|
||||
string(7) "\tHello"
|
||||
["array"]=>
|
||||
string(7) "col\tor"
|
||||
[1]=>
|
||||
string(9) "\v\fworld"
|
||||
[2]=>
|
||||
string(7) "\tHello"
|
||||
}
|
||||
-- With more arguments --
|
||||
array(7) {
|
||||
[0]=>
|
||||
string(7) "\tHello"
|
||||
["array"]=>
|
||||
array(4) {
|
||||
[0]=>
|
||||
string(7) "col\tor"
|
||||
[1]=>
|
||||
string(1) "a"
|
||||
[2]=>
|
||||
string(1) "b"
|
||||
[3]=>
|
||||
string(1) "c"
|
||||
}
|
||||
[1]=>
|
||||
string(9) "\v\fworld"
|
||||
[2]=>
|
||||
string(7) "\tHello"
|
||||
[3]=>
|
||||
string(3) "one"
|
||||
[4]=>
|
||||
int(2)
|
||||
["string"]=>
|
||||
string(5) "hello"
|
||||
}
|
||||
-- Iteration 7 --
|
||||
-- With default argument --
|
||||
array(3) {
|
||||
[0]=>
|
||||
string(5) "hello"
|
||||
["string"]=>
|
||||
string(11) "Hello world"
|
||||
[1]=>
|
||||
string(11) "Hello world"
|
||||
}
|
||||
-- With more arguments --
|
||||
array(6) {
|
||||
[0]=>
|
||||
string(5) "hello"
|
||||
["string"]=>
|
||||
array(2) {
|
||||
[0]=>
|
||||
string(11) "Hello world"
|
||||
[1]=>
|
||||
string(5) "hello"
|
||||
}
|
||||
[1]=>
|
||||
string(11) "Hello world"
|
||||
[2]=>
|
||||
string(3) "one"
|
||||
[3]=>
|
||||
int(2)
|
||||
["array"]=>
|
||||
array(3) {
|
||||
[0]=>
|
||||
string(1) "a"
|
||||
[1]=>
|
||||
string(1) "b"
|
||||
[2]=>
|
||||
string(1) "c"
|
||||
}
|
||||
}
|
||||
-- Iteration 8 --
|
||||
-- With default argument --
|
||||
array(5) {
|
||||
[0]=>
|
||||
object(classA)#%d (0) {
|
||||
}
|
||||
["string"]=>
|
||||
NULL
|
||||
["resource"]=>
|
||||
resource(%d) of type (stream)
|
||||
[1]=>
|
||||
object(classA)#%d (0) {
|
||||
}
|
||||
[2]=>
|
||||
resource(%d) of type (stream)
|
||||
}
|
||||
-- With more arguments --
|
||||
array(8) {
|
||||
[0]=>
|
||||
object(classA)#%d (0) {
|
||||
}
|
||||
["string"]=>
|
||||
array(1) {
|
||||
[0]=>
|
||||
string(5) "hello"
|
||||
}
|
||||
["resource"]=>
|
||||
resource(%d) of type (stream)
|
||||
[1]=>
|
||||
object(classA)#%d (0) {
|
||||
}
|
||||
[2]=>
|
||||
resource(%d) of type (stream)
|
||||
[3]=>
|
||||
string(3) "one"
|
||||
[4]=>
|
||||
int(2)
|
||||
["array"]=>
|
||||
array(3) {
|
||||
[0]=>
|
||||
string(1) "a"
|
||||
[1]=>
|
||||
string(1) "b"
|
||||
[2]=>
|
||||
string(1) "c"
|
||||
}
|
||||
}
|
||||
Done
|
113
ext/standard/tests/array/array_merge_recursive_variation6.phpt
Normal file
113
ext/standard/tests/array/array_merge_recursive_variation6.phpt
Normal file
@ -0,0 +1,113 @@
|
||||
--TEST--
|
||||
Test array_merge_recursive() function : usage variations - array with duplicate keys
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : array array_merge_recursive(array $arr1[, array $...])
|
||||
* Description: Recursively merges elements from passed arrays into one array
|
||||
* Source code: ext/standard/array.c
|
||||
*/
|
||||
|
||||
/*
|
||||
* Testing the functionality of array_merge_recursive() by passing
|
||||
* array having duplicate keys.
|
||||
*/
|
||||
|
||||
echo "*** Testing array_merge_recursive() : array with duplicate keys for \$arr1 argument ***\n";
|
||||
|
||||
/* initialize the array having duplicate keys */
|
||||
// array with numeric keys
|
||||
$arr1_numeric_key = array( 1 => "one", 2 => "two", 2 => array(1, 2), 3 => "three", 1 => array("duplicate", 'strings'));
|
||||
// array with string keys
|
||||
$arr1_string_key = array("str1" => "hello", "str2" => 111, "str1" => "world", "str2" => 111.111);
|
||||
|
||||
// initialize the second argument
|
||||
$arr2 = array("one", "str1" => "two", array("one", "two"));
|
||||
|
||||
echo "-- With default argument --\n";
|
||||
var_dump( array_merge_recursive($arr1_numeric_key) );
|
||||
var_dump( array_merge_recursive($arr1_string_key) );
|
||||
|
||||
echo "-- With more arguments --\n";
|
||||
var_dump( array_merge_recursive($arr1_numeric_key, $arr2) );
|
||||
var_dump( array_merge_recursive($arr1_string_key, $arr2) );
|
||||
|
||||
echo "Done";
|
||||
?>
|
||||
--EXPECTF--
|
||||
*** Testing array_merge_recursive() : array with duplicate keys for $arr1 argument ***
|
||||
-- With default argument --
|
||||
array(3) {
|
||||
[0]=>
|
||||
array(2) {
|
||||
[0]=>
|
||||
string(9) "duplicate"
|
||||
[1]=>
|
||||
string(7) "strings"
|
||||
}
|
||||
[1]=>
|
||||
array(2) {
|
||||
[0]=>
|
||||
int(1)
|
||||
[1]=>
|
||||
int(2)
|
||||
}
|
||||
[2]=>
|
||||
string(5) "three"
|
||||
}
|
||||
array(2) {
|
||||
["str1"]=>
|
||||
string(5) "world"
|
||||
["str2"]=>
|
||||
float(111.111)
|
||||
}
|
||||
-- With more arguments --
|
||||
array(6) {
|
||||
[0]=>
|
||||
array(2) {
|
||||
[0]=>
|
||||
string(9) "duplicate"
|
||||
[1]=>
|
||||
string(7) "strings"
|
||||
}
|
||||
[1]=>
|
||||
array(2) {
|
||||
[0]=>
|
||||
int(1)
|
||||
[1]=>
|
||||
int(2)
|
||||
}
|
||||
[2]=>
|
||||
string(5) "three"
|
||||
[3]=>
|
||||
string(3) "one"
|
||||
["str1"]=>
|
||||
string(3) "two"
|
||||
[4]=>
|
||||
array(2) {
|
||||
[0]=>
|
||||
string(3) "one"
|
||||
[1]=>
|
||||
string(3) "two"
|
||||
}
|
||||
}
|
||||
array(4) {
|
||||
["str1"]=>
|
||||
array(2) {
|
||||
[0]=>
|
||||
string(5) "world"
|
||||
[1]=>
|
||||
string(3) "two"
|
||||
}
|
||||
["str2"]=>
|
||||
float(111.111)
|
||||
[0]=>
|
||||
string(3) "one"
|
||||
[1]=>
|
||||
array(2) {
|
||||
[0]=>
|
||||
string(3) "one"
|
||||
[1]=>
|
||||
string(3) "two"
|
||||
}
|
||||
}
|
||||
Done
|
@ -0,0 +1,82 @@
|
||||
--TEST--
|
||||
Test array_merge_recursive() function : usage variations - array with reference variables
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : array array_merge_recursive(array $arr1[, array $...])
|
||||
* Description: Recursively merges elements from passed arrays into one array
|
||||
* Source code: ext/standard/array.c
|
||||
*/
|
||||
|
||||
/*
|
||||
* Testing the functionality of array_merge_recursive() by passing
|
||||
* array having reference variables.
|
||||
*/
|
||||
|
||||
echo "*** Testing array_merge_recursive() : array with reference variables for \$arr1 argument ***\n";
|
||||
|
||||
$value1 = 10;
|
||||
$value2 = "hello";
|
||||
$value3 = 0;
|
||||
$value4 = &$value2;
|
||||
|
||||
// input array containing elements as reference variables
|
||||
$arr1 = array(
|
||||
0 => 0,
|
||||
1 => &$value4,
|
||||
2 => &$value2,
|
||||
3 => "hello",
|
||||
4 => &$value3,
|
||||
$value4 => &$value2
|
||||
);
|
||||
|
||||
// initialize the second argument
|
||||
$arr2 = array($value4 => "hello", &$value2);
|
||||
|
||||
echo "-- With default argument --\n";
|
||||
var_dump( array_merge_recursive($arr1) );
|
||||
|
||||
echo "-- With more arguments --\n";
|
||||
var_dump( array_merge_recursive($arr1, $arr2) );
|
||||
|
||||
echo "Done";
|
||||
?>
|
||||
--EXPECTF--
|
||||
*** Testing array_merge_recursive() : array with reference variables for $arr1 argument ***
|
||||
-- With default argument --
|
||||
array(6) {
|
||||
[0]=>
|
||||
int(0)
|
||||
[1]=>
|
||||
&string(5) "hello"
|
||||
[2]=>
|
||||
&string(5) "hello"
|
||||
[3]=>
|
||||
string(5) "hello"
|
||||
[4]=>
|
||||
&int(0)
|
||||
["hello"]=>
|
||||
&string(5) "hello"
|
||||
}
|
||||
-- With more arguments --
|
||||
array(7) {
|
||||
[0]=>
|
||||
int(0)
|
||||
[1]=>
|
||||
&string(5) "hello"
|
||||
[2]=>
|
||||
&string(5) "hello"
|
||||
[3]=>
|
||||
string(5) "hello"
|
||||
[4]=>
|
||||
&int(0)
|
||||
["hello"]=>
|
||||
array(2) {
|
||||
[0]=>
|
||||
string(5) "hello"
|
||||
[1]=>
|
||||
string(5) "hello"
|
||||
}
|
||||
[5]=>
|
||||
&string(5) "hello"
|
||||
}
|
||||
Done
|
@ -0,0 +1,73 @@
|
||||
--TEST--
|
||||
Test array_merge_recursive() function : usage variations - binary safe checking
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : array array_merge_recursive(array $arr1[, array $...])
|
||||
* Description: Recursively merges elements from passed arrays into one array
|
||||
* Source code: ext/standard/array.c
|
||||
*/
|
||||
|
||||
/*
|
||||
* Testing the functionality of array_merge_recursive() by passing an array having binary values.
|
||||
*/
|
||||
|
||||
echo "*** Testing array_merge_recursive() : array with binary data for \$arr1 argument ***\n";
|
||||
|
||||
// array with binary values
|
||||
$arr1 = array(b"1", b"hello" => "hello", b"world", "str1" => b"hello", "str2" => "world");
|
||||
|
||||
// initialize the second argument
|
||||
$arr2 = array(b"str1" => b"binary", b"hello" => "binary", b"str2" => b"binary");
|
||||
|
||||
echo "-- With default argument --\n";
|
||||
var_dump( array_merge_recursive($arr1) );
|
||||
|
||||
echo "-- With more arguments --\n";
|
||||
var_dump( array_merge_recursive($arr1, $arr2) );
|
||||
|
||||
echo "Done";
|
||||
?>
|
||||
--EXPECTF--
|
||||
*** Testing array_merge_recursive() : array with binary data for $arr1 argument ***
|
||||
-- With default argument --
|
||||
array(5) {
|
||||
[0]=>
|
||||
string(1) "1"
|
||||
["hello"]=>
|
||||
string(5) "hello"
|
||||
[1]=>
|
||||
string(5) "world"
|
||||
["str1"]=>
|
||||
string(5) "hello"
|
||||
["str2"]=>
|
||||
string(5) "world"
|
||||
}
|
||||
-- With more arguments --
|
||||
array(5) {
|
||||
[0]=>
|
||||
string(1) "1"
|
||||
["hello"]=>
|
||||
array(2) {
|
||||
[0]=>
|
||||
string(5) "hello"
|
||||
[1]=>
|
||||
string(6) "binary"
|
||||
}
|
||||
[1]=>
|
||||
string(5) "world"
|
||||
["str1"]=>
|
||||
array(2) {
|
||||
[0]=>
|
||||
string(5) "hello"
|
||||
[1]=>
|
||||
string(6) "binary"
|
||||
}
|
||||
["str2"]=>
|
||||
array(2) {
|
||||
[0]=>
|
||||
string(5) "world"
|
||||
[1]=>
|
||||
string(6) "binary"
|
||||
}
|
||||
}
|
||||
Done
|
117
ext/standard/tests/array/array_merge_recursive_variation9.phpt
Normal file
117
ext/standard/tests/array/array_merge_recursive_variation9.phpt
Normal file
@ -0,0 +1,117 @@
|
||||
--TEST--
|
||||
Test array_merge_recursive() function : usage variations - common key and value(Bug#43559)
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : array array_merge_recursive(array $arr1[, array $...])
|
||||
* Description: Recursively merges elements from passed arrays into one array
|
||||
* Source code: ext/standard/array.c
|
||||
*/
|
||||
|
||||
/*
|
||||
* Testing the functionality of array_merge_recursive() by passing
|
||||
* arrays having common key and value.
|
||||
*/
|
||||
|
||||
echo "*** Testing array_merge_recursive() : arrays with common key and value ***\n";
|
||||
|
||||
/* initialize the array having duplicate values */
|
||||
|
||||
// integer values
|
||||
$arr1 = array("a" => 1, "b" => 2);
|
||||
$arr2 = array("b" => 2, "c" => 4);
|
||||
echo "-- Integer values --\n";
|
||||
var_dump( array_merge_recursive($arr1, $arr2) );
|
||||
|
||||
// float values
|
||||
$arr1 = array("a" => 1.1, "b" => 2.2);
|
||||
$arr2 = array("b" => 2.2, "c" => 3.3);
|
||||
echo "-- Float values --\n";
|
||||
var_dump( array_merge_recursive($arr1, $arr2) );
|
||||
|
||||
// string values
|
||||
$arr1 = array("a" => "hello", "b" => "world");
|
||||
$arr2 = array("b" => "world", "c" => "string");
|
||||
echo "-- String values --\n";
|
||||
var_dump( array_merge_recursive($arr1, $arr2) );
|
||||
|
||||
// boolean values
|
||||
$arr1 = array("a" => true, "b" => false);
|
||||
$arr2 = array("b" => false);
|
||||
echo "-- Boolean values --\n";
|
||||
var_dump( array_merge_recursive($arr1, $arr2) );
|
||||
|
||||
// null values
|
||||
$arr1 = array( "a" => NULL);
|
||||
$arr2 = array( "a" => NULL);
|
||||
echo "-- Null values --\n";
|
||||
var_dump( array_merge_recursive($arr1, $arr2) );
|
||||
|
||||
echo "Done";
|
||||
?>
|
||||
--EXPECTF--
|
||||
*** Testing array_merge_recursive() : arrays with common key and value ***
|
||||
-- Integer values --
|
||||
array(3) {
|
||||
["a"]=>
|
||||
int(1)
|
||||
["b"]=>
|
||||
array(2) {
|
||||
[0]=>
|
||||
int(2)
|
||||
[1]=>
|
||||
int(2)
|
||||
}
|
||||
["c"]=>
|
||||
int(4)
|
||||
}
|
||||
-- Float values --
|
||||
array(3) {
|
||||
["a"]=>
|
||||
float(1.1)
|
||||
["b"]=>
|
||||
array(2) {
|
||||
[0]=>
|
||||
float(2.2)
|
||||
[1]=>
|
||||
float(2.2)
|
||||
}
|
||||
["c"]=>
|
||||
float(3.3)
|
||||
}
|
||||
-- String values --
|
||||
array(3) {
|
||||
["a"]=>
|
||||
string(5) "hello"
|
||||
["b"]=>
|
||||
array(2) {
|
||||
[0]=>
|
||||
string(5) "world"
|
||||
[1]=>
|
||||
string(5) "world"
|
||||
}
|
||||
["c"]=>
|
||||
string(6) "string"
|
||||
}
|
||||
-- Boolean values --
|
||||
array(2) {
|
||||
["a"]=>
|
||||
bool(true)
|
||||
["b"]=>
|
||||
array(2) {
|
||||
[0]=>
|
||||
bool(false)
|
||||
[1]=>
|
||||
bool(false)
|
||||
}
|
||||
}
|
||||
-- Null values --
|
||||
array(1) {
|
||||
["a"]=>
|
||||
array(2) {
|
||||
[0]=>
|
||||
NULL
|
||||
[1]=>
|
||||
NULL
|
||||
}
|
||||
}
|
||||
Done
|
Loading…
Reference in New Issue
Block a user