New testcases for array_intersect_assoc() function

This commit is contained in:
Raghubansh Kumar 2007-11-05 14:31:40 +00:00
parent 1eb067476f
commit 49785e26ae
12 changed files with 2171 additions and 0 deletions

View File

@ -0,0 +1,69 @@
--TEST--
Test array_intersect_assoc() function : basic functionality
--FILE--
<?php
/* Prototype : array array_intersect_assoc(array $arr1, array $arr2 [, array $...])
* Description: Returns the entries of arr1 that have values which are present in all the other arguments.
* Keys are used to do more restrictive check
* Source code: ext/standard/array.c
*/
/*
* Testing the behavior of array_intersect_assoc() by passing different arrays for the arguments.
* Function is tested by passing associative array as well as array with default keys.
*/
echo "*** Testing array_intersect_assoc() : basic functionality ***\n";
// array with default keys
$arr_default_keys = array(1, 2, "hello", 'world');
// associative array
$arr_associative = array("one" => 1, "two" => 2);
// default key array for both $arr1 and $arr2 argument
var_dump( array_intersect_assoc($arr_default_keys, $arr_default_keys) );
// default key array for $arr1 and associative array for $arr2 argument
var_dump( array_intersect_assoc($arr_default_keys, $arr_associative) );
// associative array for $arr1 and default key array for $arr2
var_dump( array_intersect_assoc($arr_associative, $arr_default_keys) );
// associative array for both $arr1 and $arr2 argument
var_dump( array_intersect_assoc($arr_associative, $arr_associative) );
// more arrays to be intersected
$arr3 = array(2, 3, 4);
var_dump( array_intersect_assoc($arr_default_keys, $arr_associative, $arr3) );
var_dump( array_intersect_assoc($arr_associative, $arr_default_keys, $arr3, $arr_associative) );
echo "Done";
?>
--EXPECTF--
*** Testing array_intersect_assoc() : basic functionality ***
array(4) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
string(5) "hello"
[3]=>
string(5) "world"
}
array(0) {
}
array(0) {
}
array(2) {
["one"]=>
int(1)
["two"]=>
int(2)
}
array(0) {
}
array(0) {
}
Done

View File

@ -0,0 +1,36 @@
--TEST--
Test array_intersect_assoc() function : error conditions(Bug#43197)
--FILE--
<?php
/* Prototype : array array_intersect_assoc(array $arr1, array $arr2 [, array $...])
* Description: Returns the entries of arr1 that have values which are present in all the other arguments.
* Keys are used to do more restrictive check
* Source code: ext/standard/array.c
*/
echo "*** Testing array_intersect_assoc() : error conditions ***\n";
// Zero arguments
echo "\n-- Testing array_intersect_assoc() function with Zero arguments --\n";
var_dump( array_intersect_assoc() );
// Testing array_intersect_assoc with one less than the expected number of arguments
echo "\n-- Testing array_intersect_assoc() function with less than expected no. of arguments --\n";
$arr1 = array(1, 2);
var_dump( array_intersect_assoc($arr1) );
echo "Done";
?>
--EXPECTF--
*** Testing array_intersect_assoc() : error conditions ***
-- Testing array_intersect_assoc() function with Zero arguments --
Warning: Wrong parameter count for array_intersect_assoc() in %s on line %d
NULL
-- Testing array_intersect_assoc() function with less than expected no. of arguments --
Warning: Wrong parameter count for array_intersect_assoc() in %s on line %d
NULL
Done

View File

@ -0,0 +1,282 @@
--TEST--
Test array_intersect_assoc() function : usage variations - unexpected values for 'arr1' argument(Bug#43196)
--FILE--
<?php
/* Prototype : array array_intersect_assoc(array $arr1, array $arr2 [, array $...])
* Description: Returns the entries of arr1 that have values which are present in all the other arguments.
* Keys are used to do more restrictive check
* Source code: ext/standard/array.c
*/
/*
* Testing array_intersect_assoc() function by passing values to $arr1 argument other than arrays
* and see that function emits proper warning messages wherever expected.
* The $arr2 argument passed is a fixed array.
*/
echo "*** Testing array_intersect_assoc() : Passing non-array values to \$arr1 argument ***\n";
// array to be passsed to $arr2 as default argument
$arr2 = array(1, 2);
// additional array to be passed for intersection
$arr3 = array(1, 2, "one" => 1, "two" => 2);
// get an unset variable
$unset_var = 10;
unset ($unset_var);
// get a class
class classA
{
public function __toString() {
return "Class A 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,
// object data
/*21*/ new classA(),
// undefined data
/*22*/ @$undefined_var,
// unset data
/*23*/ @$unset_var,
// resource variable
/*24*/ $fp
);
// loop through each sub-array within $arrrays to check the behavior of array_intersect_assoc()
$iterator = 1;
foreach($arrays as $unexpected_value) {
echo "\n-- Iteration $iterator --";
// Calling array_intersect_assoc() with default arguments
var_dump( array_intersect_assoc($unexpected_value, $arr2) );
// Calling array_intersect_assoc() with more arguments
var_dump( array_intersect_assoc($unexpected_value, $arr2, $arr3) );
$iterator++;
}
// close the file resource used
fclose($fp);
echo "Done";
?>
--EXPECTF--
*** Testing array_intersect() : Passing non-array values to $arr1 argument ***
-- Iterator 1 --
Warning: array_intersect(): Argument #1 is not an array in %s on line %d
NULL
Warning: array_intersect(): Argument #1 is not an array in %s on line %d
NULL
-- Iterator 2 --
Warning: array_intersect(): Argument #1 is not an array in %s on line %d
NULL
Warning: array_intersect(): Argument #1 is not an array in %s on line %d
NULL
-- Iterator 3 --
Warning: array_intersect(): Argument #1 is not an array in %s on line %d
NULL
Warning: array_intersect(): Argument #1 is not an array in %s on line %d
NULL
-- Iterator 4 --
Warning: array_intersect(): Argument #1 is not an array in %s on line %d
NULL
Warning: array_intersect(): Argument #1 is not an array in %s on line %d
NULL
-- Iterator 5 --
Warning: array_intersect(): Argument #1 is not an array in %s on line %d
NULL
Warning: array_intersect(): Argument #1 is not an array in %s on line %d
NULL
-- Iterator 6 --
Warning: array_intersect(): Argument #1 is not an array in %s on line %d
NULL
Warning: array_intersect(): Argument #1 is not an array in %s on line %d
NULL
-- Iterator 7 --
Warning: array_intersect(): Argument #1 is not an array in %s on line %d
NULL
Warning: array_intersect(): Argument #1 is not an array in %s on line %d
NULL
-- Iterator 8 --
Warning: array_intersect(): Argument #1 is not an array in %s on line %d
NULL
Warning: array_intersect(): Argument #1 is not an array in %s on line %d
NULL
-- Iterator 9 --
Warning: array_intersect(): Argument #1 is not an array in %s on line %d
NULL
Warning: array_intersect(): Argument #1 is not an array in %s on line %d
NULL
-- Iterator 10 --
Warning: array_intersect(): Argument #1 is not an array in %s on line %d
NULL
Warning: array_intersect(): Argument #1 is not an array in %s on line %d
NULL
-- Iterator 11 --
Warning: array_intersect(): Argument #1 is not an array in %s on line %d
NULL
Warning: array_intersect(): Argument #1 is not an array in %s on line %d
NULL
-- Iterator 12 --
Warning: array_intersect(): Argument #1 is not an array in %s on line %d
NULL
Warning: array_intersect(): Argument #1 is not an array in %s on line %d
NULL
-- Iterator 13 --
Warning: array_intersect(): Argument #1 is not an array in %s on line %d
NULL
Warning: array_intersect(): Argument #1 is not an array in %s on line %d
NULL
-- Iterator 14 --
Warning: array_intersect(): Argument #1 is not an array in %s on line %d
NULL
Warning: array_intersect(): Argument #1 is not an array in %s on line %d
NULL
-- Iterator 15 --
Warning: array_intersect(): Argument #1 is not an array in %s on line %d
NULL
Warning: array_intersect(): Argument #1 is not an array in %s on line %d
NULL
-- Iterator 16 --
Warning: array_intersect(): Argument #1 is not an array in %s on line %d
NULL
Warning: array_intersect(): Argument #1 is not an array in %s on line %d
NULL
-- Iterator 17 --
Warning: array_intersect(): Argument #1 is not an array in %s on line %d
NULL
Warning: array_intersect(): Argument #1 is not an array in %s on line %d
NULL
-- Iterator 18 --
Warning: array_intersect(): Argument #1 is not an array in %s on line %d
NULL
Warning: array_intersect(): Argument #1 is not an array in %s on line %d
NULL
-- Iterator 19 --
Warning: array_intersect(): Argument #1 is not an array in %s on line %d
NULL
Warning: array_intersect(): Argument #1 is not an array in %s on line %d
NULL
-- Iterator 20 --
Warning: array_intersect(): Argument #1 is not an array in %s on line %d
NULL
Warning: array_intersect(): Argument #1 is not an array in %s on line %d
NULL
-- Iterator 21 --
Warning: array_intersect(): Argument #1 is not an array in %s on line %d
NULL
Warning: array_intersect(): Argument #1 is not an array in %s on line %d
NULL
-- Iterator 22 --
Warning: array_intersect(): Argument #1 is not an array in %s on line %d
NULL
Warning: array_intersect(): Argument #1 is not an array in %s on line %d
NULL
-- Iterator 23 --
Warning: array_intersect(): Argument #1 is not an array in %s on line %d
NULL
Warning: array_intersect(): Argument #1 is not an array in %s on line %d
NULL
-- Iterator 24 --
Warning: array_intersect(): Argument #1 is not an array in %s on line %d
NULL
Warning: array_intersect(): Argument #1 is not an array in %s on line %d
NULL
Done

View File

@ -0,0 +1,54 @@
--TEST--
Test array_intersect_assoc() function : usage variations - binary safe checking
--FILE--
<?php
/* Prototype : array array_intersect_assoc(array $arr1, array $arr2 [, array $...])
* Description: Returns the entries of arr1 that have values which are present in all the other arguments.
* Keys are used to do more restrictive check
* Source code: ext/standard/array.c
*/
/*
* Testing the behavior of array_intersect_assoc() by passing array with
* binary values for $arr1 and $arr2 argument.
*/
echo "*** Testing array_intersect_assoc() : binary safe checking ***\n";
// array with binary values
$arr_binary = array(b"hello", b"world");
// simple array
$arr_normal = array("hello", "world");
// array with binary value for $arr1 argument
var_dump( array_intersect_assoc($arr_binary, $arr_normal) );
// array with binary value for $arr2 argument
var_dump( array_intersect_assoc($arr_normal, $arr_binary) );
// array with binary value for both $arr1 and $arr2 argument
var_dump( array_intersect_assoc($arr_binary, $arr_binary) );
echo "Done";
?>
--EXPECTF--
*** Testing array_intersect_assoc() : binary safe checking ***
array(2) {
[0]=>
string(5) "hello"
[1]=>
string(5) "world"
}
array(2) {
[0]=>
string(5) "hello"
[1]=>
string(5) "world"
}
array(2) {
[0]=>
string(5) "hello"
[1]=>
string(5) "world"
}
Done

View File

@ -0,0 +1,283 @@
--TEST--
Test array_intersect_assoc() function : usage variations - unexpected values for 'arr2' argument(Bug#43196)
--FILE--
<?php
/* Prototype : array array_intersect_assoc(array $arr1, array $arr2 [, array $...])
* Description: Returns the entries of arr1 that have values which are present in all the other arguments.
* Keys are used to do more restrictive check
* Source code: ext/standard/array.c
*/
/*
* Testing array_intersect_assoc() function by passing values to $arr2 argument other than arrays
* and see that function emits proper warning messages wherever expected.
* The $arr1 argument passed is a fixed array.
*/
echo "*** Testing array_intersect_assoc() : Passing non-array values to \$arr2 argument ***\n";
// array to be passsed to $arr1 as default argument
$arr1 = array(1, 2);
// additional array to be passed for intersection
$arr3 = array(1, 2, "one" => 1, "two" => 2);
// get an unset variable
$unset_var = 10;
unset ($unset_var);
// get a class
class classA
{
public function __toString() {
return "Class A 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,
// object data
/*21*/ new classA(),
// undefined data
/*22*/ @$undefined_var,
// unset data
/*23*/ @$unset_var,
// resource variable
/*24*/ $fp
);
// loop through each sub-array within $arrrays to check the behavior of array_intersect_assoc()
$iterator = 1;
foreach($arrays as $unexpected_value) {
echo "\n-- Iteration $iterator --";
// Calling array_intersect_assoc() with default arguments
var_dump( array_intersect_assoc($arr1,$unexpected_value) );
// Calling array_intersect_assoc() with more arguments
var_dump( array_intersect_assoc($arr1, $unexpected_value, $arr3) );
$iterator++;
}
// close the file resource used
fclose($fp);
echo "Done";
?>
--EXPECTF--
*** Testing array_intersect() : Passing non-array values to $arr2 argument ***
-- Iterator 1 --
Warning: array_intersect(): Argument #2 is not an array in %s on line %d
NULL
Warning: array_intersect(): Argument #2 is not an array in %s on line %d
NULL
-- Iterator 2 --
Warning: array_intersect(): Argument #2 is not an array in %s on line %d
NULL
Warning: array_intersect(): Argument #2 is not an array in %s on line %d
NULL
-- Iterator 3 --
Warning: array_intersect(): Argument #2 is not an array in %s on line %d
NULL
Warning: array_intersect(): Argument #2 is not an array in %s on line %d
NULL
-- Iterator 4 --
Warning: array_intersect(): Argument #2 is not an array in %s on line %d
NULL
Warning: array_intersect(): Argument #2 is not an array in %s on line %d
NULL
-- Iterator 5 --
Warning: array_intersect(): Argument #2 is not an array in %s on line %d
NULL
Warning: array_intersect(): Argument #2 is not an array in %s on line %d
NULL
-- Iterator 6 --
Warning: array_intersect(): Argument #2 is not an array in %s on line %d
NULL
Warning: array_intersect(): Argument #2 is not an array in %s on line %d
NULL
-- Iterator 7 --
Warning: array_intersect(): Argument #2 is not an array in %s on line %d
NULL
Warning: array_intersect(): Argument #2 is not an array in %s on line %d
NULL
-- Iterator 8 --
Warning: array_intersect(): Argument #2 is not an array in %s on line %d
NULL
Warning: array_intersect(): Argument #2 is not an array in %s on line %d
NULL
-- Iterator 9 --
Warning: array_intersect(): Argument #2 is not an array in %s on line %d
NULL
Warning: array_intersect(): Argument #2 is not an array in %s on line %d
NULL
-- Iterator 10 --
Warning: array_intersect(): Argument #2 is not an array in %s on line %d
NULL
Warning: array_intersect(): Argument #2 is not an array in %s on line %d
NULL
-- Iterator 11 --
Warning: array_intersect(): Argument #2 is not an array in %s on line %d
NULL
Warning: array_intersect(): Argument #2 is not an array in %s on line %d
NULL
-- Iterator 12 --
Warning: array_intersect(): Argument #2 is not an array in %s on line %d
NULL
Warning: array_intersect(): Argument #2 is not an array in %s on line %d
NULL
-- Iterator 13 --
Warning: array_intersect(): Argument #2 is not an array in %s on line %d
NULL
Warning: array_intersect(): Argument #2 is not an array in %s on line %d
NULL
-- Iterator 14 --
Warning: array_intersect(): Argument #2 is not an array in %s on line %d
NULL
Warning: array_intersect(): Argument #2 is not an array in %s on line %d
NULL
-- Iterator 15 --
Warning: array_intersect(): Argument #2 is not an array in %s on line %d
NULL
Warning: array_intersect(): Argument #2 is not an array in %s on line %d
NULL
-- Iterator 16 --
Warning: array_intersect(): Argument #2 is not an array in %s on line %d
NULL
Warning: array_intersect(): Argument #2 is not an array in %s on line %d
NULL
-- Iterator 17 --
Warning: array_intersect(): Argument #2 is not an array in %s on line %d
NULL
Warning: array_intersect(): Argument #2 is not an array in %s on line %d
NULL
-- Iterator 18 --
Warning: array_intersect(): Argument #2 is not an array in %s on line %d
NULL
Warning: array_intersect(): Argument #2 is not an array in %s on line %d
NULL
-- Iterator 19 --
Warning: array_intersect(): Argument #2 is not an array in %s on line %d
NULL
Warning: array_intersect(): Argument #2 is not an array in %s on line %d
NULL
-- Iterator 20 --
Warning: array_intersect(): Argument #2 is not an array in %s on line %d
NULL
Warning: array_intersect(): Argument #2 is not an array in %s on line %d
NULL
-- Iterator 21 --
Warning: array_intersect(): Argument #2 is not an array in %s on line %d
NULL
Warning: array_intersect(): Argument #2 is not an array in %s on line %d
NULL
-- Iterator 22 --
Warning: array_intersect(): Argument #2 is not an array in %s on line %d
NULL
Warning: array_intersect(): Argument #2 is not an array in %s on line %d
NULL
-- Iterator 23 --
Warning: array_intersect(): Argument #2 is not an array in %s on line %d
NULL
Warning: array_intersect(): Argument #2 is not an array in %s on line %d
NULL
-- Iterator 24 --
Warning: array_intersect(): Argument #2 is not an array in %s on line %d
NULL
Warning: array_intersect(): Argument #2 is not an array in %s on line %d
NULL
Done

View File

@ -0,0 +1,245 @@
--TEST--
Test array_intersect_assoc() function : usage variations - different arrays for 'arr1' argument
--FILE--
<?php
/* Prototype : array array_intersect_assoc(array $arr1, array $arr2 [, array $...])
* Description: Returns the entries of arr1 that have values which are present in all the other arguments.
* Keys are used to do more restrictive check
* Source code: ext/standard/array.c
*/
/*
* Passing different types of arrays to $arr1 argument and testing whether
* array_intersect_assoc() behaves in an expected way with the other arguments passed to the function
* The $arr2 argument passed is a fixed array.
*/
echo "*** Testing array_intersect_assoc() : Passing different types of arrays to \$arr1 argument ***\n";
/* Different heredoc strings passed as argument to $arr1 */
// heredoc with blank line
$blank_line = <<<EOT
EOT;
// heredoc with multiline string
$multiline_string = <<<EOT
hello world
The big 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 to be 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","b\tbbb","c","\[\]\!\@\#\$\%\^\&\*\(\)\{\}"), // with double quoted strings
array('a\v\f','aaaa\r','b','b\tbbb','c','\[\]\!\@\#\$\%\^\&\*\(\)\{\}'), // with single quoted strings
array("h1" => $blank_line, "h2" => $multiline_string, "h3" => $diff_whitespaces, $numeric_string), // with heredocs
// associative arrays
/*9*/ array(1 => "one", 2 => "two", 3 => "three"), // explicit numeric keys, string values
array("one" => 1, "two" => 2, "three" => 3 ), // string keys & numeric values
array( 1 => 10, 2 => 20, 4 => 40, 3 => 30), // explicit numeric keys and numeric values
array( "one" => "ten", "two" => "twenty", "three" => "thirty"), // 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 with repetative keys
/*19*/ array("One" => 1, "two" => 2, "One" => 10, "two" => 20, "three" => 3)
);
// array to be passsed to $arr2 argument
$arr2 = array (
1, 1.1, 2.2, "hello", "one", NULL, 2,
'world', true,5 => false, 1 => 'aaaa\r', "aaaa\r",
'h3' => $diff_whitespaces, $numeric_string,
"one" => "ten", 4 => "four", "two" => 2,
'', null => "null", '' => 'emptys', "emptyd" => "",
);
// loop through each sub-array within $arrrays to check the behavior of array_intersect_assoc()
$iterator = 1;
foreach($arrays as $arr1) {
echo "-- Iteration $iterator --\n";
// Calling array_intersect_assoc() with default arguments
var_dump( array_intersect_assoc($arr1, $arr2) );
// Calling array_intersect_assoc() with more arguments.
// additional argument passed is the same as $arr1 argument
var_dump( array_intersect_assoc($arr1, $arr2, $arr1) );
$iterator++;
}
echo "Done";
?>
--EXPECTF--
*** Testing array_intersect_assoc() : Passing different types of arrays to $arr1 argument ***
-- Iteration 1 --
array(1) {
[0]=>
int(1)
}
array(1) {
[0]=>
int(1)
}
-- Iteration 2 --
array(0) {
}
array(0) {
}
-- Iteration 3 --
array(0) {
}
array(0) {
}
-- Iteration 4 --
array(0) {
}
array(0) {
}
-- Iteration 5 --
array(0) {
}
array(0) {
}
-- Iteration 6 --
array(0) {
}
array(0) {
}
-- Iteration 7 --
array(1) {
[1]=>
string(6) "aaaa\r"
}
array(1) {
[1]=>
string(6) "aaaa\r"
}
-- Iteration 8 --
array(1) {
["h3"]=>
string(88) "hello
world
1111 != 2222
heredoc
double quoted string. with different white spaces"
}
array(1) {
["h3"]=>
string(88) "hello
world
1111 != 2222
heredoc
double quoted string. with different white spaces"
}
-- Iteration 9 --
array(0) {
}
array(0) {
}
-- Iteration 10 --
array(1) {
["two"]=>
int(2)
}
array(1) {
["two"]=>
int(2)
}
-- Iteration 11 --
array(0) {
}
array(0) {
}
-- Iteration 12 --
array(1) {
["one"]=>
string(3) "ten"
}
array(1) {
["one"]=>
string(3) "ten"
}
-- Iteration 13 --
array(1) {
[4]=>
string(4) "four"
}
array(1) {
[4]=>
string(4) "four"
}
-- Iteration 14 --
array(0) {
}
array(0) {
}
-- Iteration 15 --
array(0) {
}
array(0) {
}
-- Iteration 16 --
array(2) {
[""]=>
string(6) "emptys"
["emptyd"]=>
string(0) ""
}
array(2) {
[""]=>
string(6) "emptys"
["emptyd"]=>
string(0) ""
}
-- Iteration 17 --
array(1) {
[5]=>
bool(false)
}
array(1) {
[5]=>
bool(false)
}
-- Iteration 18 --
array(0) {
}
array(0) {
}
-- Iteration 19 --
array(0) {
}
array(0) {
}
Done

View File

@ -0,0 +1,256 @@
--TEST--
Test array_intersect_assoc() function : usage variations - different arrays for 'arr2' argument
--FILE--
<?php
/* Prototype : array array_intersect_assoc(array $arr1, array $arr2 [, array $...])
* Description: Returns the entries of arr1 that have values which are present in all the other arguments.
* Keys are used to do more restrictive check
* Source code: ext/standard/array.c
*/
/*
* Passing different types of arrays to $arr2 argument and testing whether
* array_intersect_assoc() behaves in an expected way with the other arguments passed to the function.
* The $arr1 argument passed is a fixed array.
*/
echo "*** Testing array_intersect_assoc() : Passing different types of arrays to \$arr2 argument ***\n";
/* Different heredoc strings passed as argument to $arr2 */
// heredoc with blank line
$blank_line = <<<EOT
EOT;
// heredoc with multiline string
$multiline_string = <<<EOT
hello world
The big 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;
// array to be passsed to $arr1 argument
$arr1 = array (
1, 1.1, 1.3, 1 => true, "hello", "one", NULL, 2,
'world', true, false, 3 => "b\tbbb", "aaaa\r",
$numeric_string, "h3" => $diff_whitespaces, "true" => true,
"one" => "ten", 4 => "four", "two" => 2, 6 => "six",
'', null => "null", '' => 'emptys'
);
// arrays to be passed to $arr2 argument
$arrays = array (
/*1*/ array(1, 2), // array with default keys and numeric values
array(1.1, 1.2, 1.3), // array with default keys & float values
array(false,true), // array with default keys and boolean values
array(), // empty array
/*5*/ array(NULL), // array with NULL
array("a\v\f","aaaa\r","b","b\tbbb","c","\[\]\!\@\#\$\%\^\&\*\(\)\{\}"), // array with double quoted strings
array('a\v\f','aaaa\r','b','b\tbbb','c','\[\]\!\@\#\$\%\^\&\*\(\)\{\}'), // array with single quoted strings
array($blank_line, "h2" => $multiline_string, "h3" => $diff_whitespaces, $numeric_string), // array with heredocs
// associative arrays
/*9*/ array(1 => "one", 2 => "two", 6 => "six"), // explicit numeric keys, string values
array("one" => 1, "two" => 2, "three" => 3 ), // string keys & numeric values
array( 1 => 10, 2 => 20, 4 => 40, 3 => 30), // explicit numeric keys and numeric values
array( "one" => "ten", "two" => "twenty", "three" => "thirty"), // 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 with repetative keys
/*19*/ array("One" => 1, "two" => 2, "One" => 10, "two" => 20, "three" => 3)
);
// loop through each sub-array within $arrrays to check the behavior of array_intersect_assoc()
$iterator = 1;
foreach($arrays as $arr2) {
echo "-- Iteration $iterator --\n";
// Calling array_intersect_assoc() with default arguments
var_dump( array_intersect_assoc($arr1, $arr2) );
// Calling array_intersect_assoc() with more arguments
// additional argument passed is the same as $arr1 argument
var_dump( array_intersect_assoc($arr1, $arr2, $arr1) );
$iterator++;
}
echo "Done";
?>
--EXPECTF--
*** Testing array_intersect_assoc() : Passing different types of arrays to $arr2 argument ***
-- Iteration 1 --
array(1) {
[0]=>
int(1)
}
array(1) {
[0]=>
int(1)
}
-- Iteration 2 --
array(1) {
[2]=>
float(1.3)
}
array(1) {
[2]=>
float(1.3)
}
-- Iteration 3 --
array(1) {
[1]=>
bool(true)
}
array(1) {
[1]=>
bool(true)
}
-- Iteration 4 --
array(0) {
}
array(0) {
}
-- Iteration 5 --
array(0) {
}
array(0) {
}
-- Iteration 6 --
array(1) {
[3]=>
string(5) "b bbb"
}
array(1) {
[3]=>
string(5) "b bbb"
}
-- Iteration 7 --
array(0) {
}
array(0) {
}
-- Iteration 8 --
array(1) {
["h3"]=>
string(88) "hello
world
1111 != 2222
heredoc
double quoted string. with different white spaces"
}
array(1) {
["h3"]=>
string(88) "hello
world
1111 != 2222
heredoc
double quoted string. with different white spaces"
}
-- Iteration 9 --
array(1) {
[6]=>
string(3) "six"
}
array(1) {
[6]=>
string(3) "six"
}
-- Iteration 10 --
array(1) {
["two"]=>
int(2)
}
array(1) {
["two"]=>
int(2)
}
-- Iteration 11 --
array(0) {
}
array(0) {
}
-- Iteration 12 --
array(1) {
["one"]=>
string(3) "ten"
}
array(1) {
["one"]=>
string(3) "ten"
}
-- Iteration 13 --
array(1) {
[4]=>
string(4) "four"
}
array(1) {
[4]=>
string(4) "four"
}
-- Iteration 14 --
array(0) {
}
array(0) {
}
-- Iteration 15 --
array(1) {
["true"]=>
bool(true)
}
array(1) {
["true"]=>
bool(true)
}
-- Iteration 16 --
array(1) {
[""]=>
string(6) "emptys"
}
array(1) {
[""]=>
string(6) "emptys"
}
-- Iteration 17 --
array(1) {
[5]=>
NULL
}
array(1) {
[5]=>
NULL
}
-- Iteration 18 --
array(0) {
}
array(0) {
}
-- Iteration 19 --
array(0) {
}
array(0) {
}
Done

View File

@ -0,0 +1,197 @@
--TEST--
Test array_intersect_assoc() function : usage variations - assoc array with diff keys for 'arr1' argument
--FILE--
<?php
/* Prototype : array array_intersect_assoc(array $arr1, array $arr2 [, array $...])
* Description: Returns the entries of arr1 that have values which are present in all the other arguments.
* Keys are used to do more restrictive check
* Source code: ext/standard/array.c
*/
/*
* Testing the functionality of array_intersect_assoc() by passing different
* associative arrays having different possible keys to $arr1 argument.
* The $arr2 argument passed is a fixed array
*/
echo "*** Testing array_intersect_assoc() : 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 variations of associative arrays to be passed to $arr1 argument
$arrays = array (
// empty array
/*1*/ array(),
// arrays with integer keys
array(0 => "0"),
array(1 => "1"),
array(1 => "1", 2 => "2", 3 => "3", 4 => "4"),
// arrays with float keys
/*5*/ array(2.3333 => "float"),
array(1.2 => "f1", 3.33 => "f2",
4.89999922839999 => "f3",
33333333.333333 => "f4"),
// arrays with string keys
/*7*/ array('\tHello' => 111, 're\td' => "color",
'\v\fworld' => 2.2, 'pen\n' => 33),
array("\tHello" => 111, "re\td" => "color",
"\v\fworld" => 2.2, "pen\n" => 33),
array("hello", $heredoc => "string"), // heredoc
// array with object, unset variable and resource variable
/*10*/ array(new classA() => 11, @$unset_var => "hello", $fp => 'resource'),
// array with mixed keys
/*11*/ array('hello' => 1, new classA() => 2, "fruit" => 2.2,
$fp => 'resource', 133 => "int", 444.432 => "float",
@$unset_var => "unset", $heredoc => "heredoc")
);
// array to be passsed to $arr2 argument
$arr2 = array(0 => 0, 2 => "float", 4 => "f3", 33333333 => "f4",
"\tHello" => 111, 2.2, 'color', "Hello world" => "string",
"pen\n" => 33, new classA() => 11, 133 => "int");
// loop through each sub-array within $arrrays to check the behavior of array_intersect_assoc()
$iterator = 1;
foreach($arrays as $arr1) {
echo "-- Iteration $iterator --\n";
// Calling array_intersect_assoc() with default arguments
var_dump( array_intersect_assoc($arr1, $arr2) );
// Calling array_intersect_assoc() with more arguments.
// additional argument passed is the same as $arr1 argument
var_dump( array_intersect_assoc($arr1, $arr2, $arr1) );
$iterator++;
}
// close the file resource used
fclose($fp);
echo "Done";
?>
--EXPECTF--
*** Testing array_intersect_assoc() : 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
Warning: Illegal offset type in %s on line %d
Warning: Illegal offset type in %s on line %d
Warning: Illegal offset type in %s on line %d
-- Iteration 1 --
array(0) {
}
array(0) {
}
-- Iteration 2 --
array(1) {
[0]=>
string(1) "0"
}
array(1) {
[0]=>
string(1) "0"
}
-- Iteration 3 --
array(0) {
}
array(0) {
}
-- Iteration 4 --
array(0) {
}
array(0) {
}
-- Iteration 5 --
array(1) {
[2]=>
string(5) "float"
}
array(1) {
[2]=>
string(5) "float"
}
-- Iteration 6 --
array(2) {
[4]=>
string(2) "f3"
[33333333]=>
string(2) "f4"
}
array(2) {
[4]=>
string(2) "f3"
[33333333]=>
string(2) "f4"
}
-- Iteration 7 --
array(0) {
}
array(0) {
}
-- Iteration 8 --
array(2) {
[" Hello"]=>
int(111)
["pen
"]=>
int(33)
}
array(2) {
[" Hello"]=>
int(111)
["pen
"]=>
int(33)
}
-- Iteration 9 --
array(1) {
["Hello world"]=>
string(6) "string"
}
array(1) {
["Hello world"]=>
string(6) "string"
}
-- Iteration 10 --
array(0) {
}
array(0) {
}
-- Iteration 11 --
array(1) {
[133]=>
string(3) "int"
}
array(1) {
[133]=>
string(3) "int"
}
Done

View File

@ -0,0 +1,197 @@
--TEST--
Test array_intersect_assoc() function : usage variations - assoc array with diff keys for 'arr2' argument
--FILE--
<?php
/* Prototype : array array_intersect_assoc(array $arr1, array $arr2 [, array $...])
* Description: Returns the entries of arr1 that have values which are present in all the other arguments.
* Keys are used to do more restrictive check
* Source code: ext/standard/array.c
*/
/*
* Testing the functionality of array_intersect_assoc() by passing different
* associative arrays having different possible keys to $arr2 argument.
* The $arr1 argument passed is a fixed array.
*/
echo "*** Testing array_intersect_assoc() : assoc array with diff keys to \$arr2 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 variations of associative arrays to be passed to $arr2 argument
$arrays = array (
// empty array
/*1*/ array(),
// arrays with integer keys
array(0 => "0"),
array(1 => "1"),
array(1 => "1", 2 => "2", 3 => "3", 4 => "4"),
// arrays with float keys
/*5*/ array(2.3333 => "float"),
array(1.2 => "f1", 3.33 => "f2",
4.89999922839999 => "f3",
33333333.333333 => "f4"),
// arrays with string keys
/*7*/ array('\tHello' => 111, 're\td' => "color",
'\v\fworld' => 2.2, 'pen\n' => 33),
array("\tHello" => 111, "re\td" => "color",
"\v\fworld" => 2.2, "pen\n" => 33),
array("hello", $heredoc => "string"), // heredoc
// array with object, unset variable and resource variable
/*10*/ array(new classA() => 11, @$unset_var => "hello", $fp => 'resource'),
// array with mixed keys
/*11*/ array('hello' => 1, new classA() => 2, "fruit" => 2.2,
$fp => 'resource', 133 => "int", 444.432 => "float",
@$unset_var => "unset", $heredoc => "heredoc")
);
// array to be passsed to $arr1 argument
$arr1 = array(0 => 0, 2 => "float", 4 => "f3", 33333333 => "f4",
"\tHello" => 111, 2.2, 'color', "Hello world" => "string",
"pen\n" => 33, new classA() => 11, 133 => "int");
// loop through each sub-array within $arrrays to check the behavior of array_intersect_assoc()
$iterator = 1;
foreach($arrays as $arr2) {
echo "-- Iteration $iterator --\n";
// Calling array_intersect_assoc() with default arguments
var_dump( array_intersect_assoc($arr1, $arr2) );
// Calling array_intersect_assoc() with more arguments.
// additional argument passed is the same as $arr1 argument
var_dump( array_intersect_assoc($arr1, $arr2, $arr1) );
$iterator++;
}
// close the file resource used
fclose($fp);
echo "Done";
?>
--EXPECTF--
*** Testing array_intersect_assoc() : assoc array with diff keys to $arr2 argument ***
Warning: Illegal offset type in %s on line %d
Warning: Illegal offset type in %s on line %d
Warning: Illegal offset type in %s on line %d
Warning: Illegal offset type in %s on line %d
Warning: Illegal offset type in %s on line %d
-- Iteration 1 --
array(0) {
}
array(0) {
}
-- Iteration 2 --
array(1) {
[0]=>
int(0)
}
array(1) {
[0]=>
int(0)
}
-- Iteration 3 --
array(0) {
}
array(0) {
}
-- Iteration 4 --
array(0) {
}
array(0) {
}
-- Iteration 5 --
array(1) {
[2]=>
string(5) "float"
}
array(1) {
[2]=>
string(5) "float"
}
-- Iteration 6 --
array(2) {
[4]=>
string(2) "f3"
[33333333]=>
string(2) "f4"
}
array(2) {
[4]=>
string(2) "f3"
[33333333]=>
string(2) "f4"
}
-- Iteration 7 --
array(0) {
}
array(0) {
}
-- Iteration 8 --
array(2) {
[" Hello"]=>
int(111)
["pen
"]=>
int(33)
}
array(2) {
[" Hello"]=>
int(111)
["pen
"]=>
int(33)
}
-- Iteration 9 --
array(1) {
["Hello world"]=>
string(6) "string"
}
array(1) {
["Hello world"]=>
string(6) "string"
}
-- Iteration 10 --
array(0) {
}
array(0) {
}
-- Iteration 11 --
array(1) {
[133]=>
string(3) "int"
}
array(1) {
[133]=>
string(3) "int"
}
Done

View File

@ -0,0 +1,212 @@
--TEST--
Test array_intersect_assoc() function : usage variations - assoc array with diff values for 'arr1' argument
--FILE--
<?php
/* Prototype : array array_intersect_assoc(array $arr1, array $arr2 [, array $...])
* Description: Returns the entries of arr1 that have values which are present in all the other arguments.
* Keys are used to do more restrictive check
* Source code: ext/standard/array.c
*/
/*
* Testing the functionality of array_intersect_assoc() by passing different
* associative arrays having different possible values to $arr1 argument.
* The $arr2 argument passed is a fixed array
*/
echo "*** Testing array_intersect_assoc() : 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 variations of associative arrays to be passed to $arr1 argument
$arrays = array (
// empty array
/*1*/ array(),
// arrays with integer values
array('0' => 0),
array("1" => 1),
array("one" => 1, 'two' => 2, "three" => 3, 4 => 4),
// arrays with float values
/*5*/ array("float" => 2.3333),
array("f1" => 1.2, 'f2' => 3.33, 3 => 4.89999922839999, 'f4' => 33333333.333),
// arrays with string values
/*7*/ array(111 => "\tHello", "red" => "col\tor", 2 => "\v\fworld", 3.3 => "pen\n"),
array(111 => '\tHello', "red" => 'col\tor', 2 => '\v\fworld', 3.3 => 'pen\n'),
array(1 => "hello", "heredoc" => $heredoc),
// array with object, unset variable and resource variable
/*10*/ array(11 => new classA(), "unset" => @$unset_var, "resource" => $fp),
// array with mixed values
/*11*/ array(1 => 'hello', 2 => new classA(), 222 => "fruit",
'resource' => $fp, "int" => 133, "float" => 444.432,
"unset" => @$unset_var, "heredoc" => $heredoc)
);
// array to be passsed to $arr2 argument
$arr2 = array(0 => "0", 1, "two" => 2, "float" => 2.3333, "f1" => 1.2,
"f4" => 33333333.333, 111 => "\tHello", 3.3 => 'pen\n', '\v\fworld',
"heredoc" => "Hello world", 11 => new classA(), "resource" => $fp,
"int" => 133, 222 => "fruit");
// loop through each sub-array within $arrrays to check the behavior of array_intersect_assoc()
$iterator = 1;
foreach($arrays as $arr1) {
echo "-- Iteration $iterator --\n";
// Calling array_intersect_assoc() with default arguments
var_dump( array_intersect_assoc($arr1, $arr2) );
// Calling array_intersect_assoc() with more arguments.
// additional argument passed is the same as $arr1 argument
var_dump( array_intersect_assoc($arr1, $arr2, $arr1) );
$iterator++;
}
// close the file resource used
fclose($fp);
echo "Done";
?>
--EXPECTF--
*** Testing array_intersect_assoc() : assoc array with diff values to $arr1 argument ***
-- Iteration 1 --
array(0) {
}
array(0) {
}
-- Iteration 2 --
array(1) {
[0]=>
int(0)
}
array(1) {
[0]=>
int(0)
}
-- Iteration 3 --
array(1) {
[1]=>
int(1)
}
array(1) {
[1]=>
int(1)
}
-- Iteration 4 --
array(1) {
["two"]=>
int(2)
}
array(1) {
["two"]=>
int(2)
}
-- Iteration 5 --
array(1) {
["float"]=>
float(2.3333)
}
array(1) {
["float"]=>
float(2.3333)
}
-- Iteration 6 --
array(2) {
["f1"]=>
float(1.2)
["f4"]=>
float(33333333.333)
}
array(2) {
["f1"]=>
float(1.2)
["f4"]=>
float(33333333.333)
}
-- Iteration 7 --
array(1) {
[111]=>
string(6) " Hello"
}
array(1) {
[111]=>
string(6) " Hello"
}
-- Iteration 8 --
array(1) {
[3]=>
string(5) "pen\n"
}
array(1) {
[3]=>
string(5) "pen\n"
}
-- Iteration 9 --
array(1) {
["heredoc"]=>
string(11) "Hello world"
}
array(1) {
["heredoc"]=>
string(11) "Hello world"
}
-- Iteration 10 --
array(2) {
[11]=>
object(classA)#%d (0) {
}
["resource"]=>
resource(%d) of type (stream)
}
array(2) {
[11]=>
object(classA)#%d (0) {
}
["resource"]=>
resource(%d) of type (stream)
}
-- Iteration 11 --
array(4) {
[222]=>
string(5) "fruit"
["resource"]=>
resource(%d) of type (stream)
["int"]=>
int(133)
["heredoc"]=>
string(11) "Hello world"
}
array(4) {
[222]=>
string(5) "fruit"
["resource"]=>
resource(%d) of type (stream)
["int"]=>
int(133)
["heredoc"]=>
string(11) "Hello world"
}
Done

View File

@ -0,0 +1,212 @@
--TEST--
Test array_intersect_assoc() function : usage variations - assoc array with diff values for 'arr2' argument
--FILE--
<?php
/* Prototype : array array_intersect_assoc(array $arr1, array $arr2 [, array $...])
* Description: Returns the entries of arr1 that have values which are present in all the other arguments.
* Keys are used to do more restrictive check
* Source code: ext/standard/array.c
*/
/*
* Testing the functionality of array_intersect_assoc() by passing different
* associative arrays having different possible values to $arr2 argument.
* The $arr1 argument passed is a fixed array.
*/
echo "*** Testing array_intersect_assoc() : assoc array with diff values to \$arr2 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 variations of associative arrays to be passed to $arr2 argument
$arrays = array (
// empty array
/*1*/ array(),
// arrays with integer values
array('0' => 0),
array("1" => 1),
array("one" => 1, 'two' => 2, "three" => 3, 4 => 4),
// arrays with float values
/*5*/ array("float" => 2.3333),
array("f1" => 1.2, 'f2' => 3.33, 3 => 4.89999922839999, 'f4' => 33333333.333),
// arrays with string values
/*7*/ array(111 => "\tHello", "red" => "col\tor", 2 => "\v\fworld", 3.3 => "pen\n"),
array(111 => '\tHello', "red" => 'col\tor', 2 => '\v\fworld', 3.3 => 'pen\n'),
array(1 => "hello", "heredoc" => $heredoc),
// array with object, unset variable and resource variable
/*10*/ array(11 => new classA(), "unset" => @$unset_var, "resource" => $fp),
// array with mixed values
/*11*/ array(1 => 'hello', 2 => new classA(), 222 => "fruit",
'resource' => $fp, "int" => 133, "float" => 444.432,
"unset" => @$unset_var, "heredoc" => $heredoc)
);
// array to be passsed to $arr1 argument
$arr1 = array(0 => "0", 1, "two" => 2, "float" => 2.3333, "f1" => 1.2,
"f4" => 33333333.333, 111 => "\tHello", 3.3 => 'pen\n', '\v\fworld',
"heredoc" => "Hello world", 11 => new classA(), "resource" => $fp,
"int" => 133, 222 => "fruit");
// loop through each sub-array within $arrrays to check the behavior of array_intersect_assoc()
$iterator = 1;
foreach($arrays as $arr2) {
echo "-- Iteration $iterator --\n";
// Calling array_intersect_assoc() with default arguments
var_dump( array_intersect_assoc($arr1, $arr2) );
// Calling array_intersect_assoc() with more arguments.
// additional argument passed is the same as $arr1 argument
var_dump( array_intersect_assoc($arr1, $arr2, $arr1) );
$iterator++;
}
// close the file resource used
fclose($fp);
echo "Done";
?>
--EXPECTF--
*** Testing array_intersect_assoc() : assoc array with diff values to $arr2 argument ***
-- Iteration 1 --
array(0) {
}
array(0) {
}
-- Iteration 2 --
array(1) {
[0]=>
string(1) "0"
}
array(1) {
[0]=>
string(1) "0"
}
-- Iteration 3 --
array(1) {
[1]=>
int(1)
}
array(1) {
[1]=>
int(1)
}
-- Iteration 4 --
array(1) {
["two"]=>
int(2)
}
array(1) {
["two"]=>
int(2)
}
-- Iteration 5 --
array(1) {
["float"]=>
float(2.3333)
}
array(1) {
["float"]=>
float(2.3333)
}
-- Iteration 6 --
array(2) {
["f1"]=>
float(1.2)
["f4"]=>
float(33333333.333)
}
array(2) {
["f1"]=>
float(1.2)
["f4"]=>
float(33333333.333)
}
-- Iteration 7 --
array(1) {
[111]=>
string(6) " Hello"
}
array(1) {
[111]=>
string(6) " Hello"
}
-- Iteration 8 --
array(1) {
[3]=>
string(5) "pen\n"
}
array(1) {
[3]=>
string(5) "pen\n"
}
-- Iteration 9 --
array(1) {
["heredoc"]=>
string(11) "Hello world"
}
array(1) {
["heredoc"]=>
string(11) "Hello world"
}
-- Iteration 10 --
array(2) {
[11]=>
object(classA)#%d (0) {
}
["resource"]=>
resource(%d) of type (stream)
}
array(2) {
[11]=>
object(classA)#%d (0) {
}
["resource"]=>
resource(%d) of type (stream)
}
-- Iteration 11 --
array(4) {
["heredoc"]=>
string(11) "Hello world"
["resource"]=>
resource(%d) of type (stream)
["int"]=>
int(133)
[222]=>
string(5) "fruit"
}
array(4) {
["heredoc"]=>
string(11) "Hello world"
["resource"]=>
resource(%d) of type (stream)
["int"]=>
int(133)
[222]=>
string(5) "fruit"
}
Done

View File

@ -0,0 +1,128 @@
--TEST--
Test array_intersect_assoc() function : usage variations - two dimensional arrays for $arr1 and $arr2 arguments
--FILE--
<?php
/* Prototype : array array_intersect_assoc(array $arr1, array $arr2 [, array $...])
* Description: Returns the entries of arr1 that have values which are present in all the other arguments.
* Keys are used to do more restrictive check
* Source code: ext/standard/array.c
*/
/*
* Testing the behavior of array_intersect_assoc() by passing 2-D arrays
* to both $arr1 and $arr2 argument.
* Optional argument takes the same value as that of $arr1
*/
echo "*** Testing array_intersect_assoc() : passing two dimensional array to both \$arr1 and \$arr2 arguments ***\n";
// two dimensional arrays for $arr1 and $arr2 argument
$arr1 = array (
// arrays with default keys
array(1, 2, "hello", 'world'),
array(1, 2, 3, 4),
// arrays with explicit keys
array(1 => "one", 2 => "two", 3 => "three"),
array("ten" => 10, "twenty" => 20.00, "thirty" => 30)
);
$arr2 = array (
array(1, 2, 3, 4),
array(1 => "one", 2 => "two", 3 => "three")
);
/* Passing the entire array as argument to $arr1 and $arr2 */
// Calling array_intersect_assoc() with default arguments
echo "-- Passing the entire 2-D array to \$arr1 and \$arr2 --\n";
echo "- With default arguments -\n";
var_dump( array_intersect_assoc($arr1, $arr2) );
// Calling array_intersect_assoc() with more arguments
// additional argument passed is the same as $arr1
echo "- With more arguments -\n";
var_dump( array_intersect_assoc($arr1, $arr2, $arr1) );
/* Passing the sub-array as argument to $arr1 and $arr2 */
// Calling array_intersect_assoc() with default arguments
echo "-- Passing the sub-array to \$arr1 and \$arr2 --\n";
echo "- With default arguments -\n";
var_dump( array_intersect_assoc($arr1[0], $arr2[0]) );
// Calling array_intersect_assoc() with more arguments
// additional argument passed is the same as $arr1
echo "- With more arguments -\n";
var_dump( array_intersect_assoc($arr1[0], $arr2[0], $arr1[0]) );
echo "Done";
?>
--EXPECTF--
*** Testing array_intersect_assoc() : passing two dimensional array to both $arr1 and $arr2 arguments ***
-- Passing the entire 2-D array to $arr1 and $arr2 --
- With default arguments -
array(2) {
[0]=>
array(4) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
string(5) "hello"
[3]=>
string(5) "world"
}
[1]=>
array(4) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
[3]=>
int(4)
}
}
- With more arguments -
array(2) {
[0]=>
array(4) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
string(5) "hello"
[3]=>
string(5) "world"
}
[1]=>
array(4) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
[3]=>
int(4)
}
}
-- Passing the sub-array to $arr1 and $arr2 --
- With default arguments -
array(2) {
[0]=>
int(1)
[1]=>
int(2)
}
- With more arguments -
array(2) {
[0]=>
int(1)
[1]=>
int(2)
}
Done