Annotation of embedaddon/php/ext/standard/tests/array/array_intersect_assoc_variation6.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Test array_intersect_assoc() function : usage variations - assoc array with diff keys for 'arr2' argument
! 3: --FILE--
! 4: <?php
! 5: /* Prototype : array array_intersect_assoc(array $arr1, array $arr2 [, array $...])
! 6: * Description: Returns the entries of arr1 that have values which are present in all the other arguments.
! 7: * Keys are used to do more restrictive check
! 8: * Source code: ext/standard/array.c
! 9: */
! 10:
! 11: /*
! 12: * Testing the functionality of array_intersect_assoc() by passing different
! 13: * associative arrays having different possible keys to $arr2 argument.
! 14: * The $arr1 argument passed is a fixed array.
! 15: */
! 16:
! 17: echo "*** Testing array_intersect_assoc() : assoc array with diff keys to \$arr2 argument ***\n";
! 18:
! 19: // get an unset variable
! 20: $unset_var = 10;
! 21: unset ($unset_var);
! 22:
! 23: // get a heredoc string
! 24: $heredoc = <<<EOT
! 25: Hello world
! 26: EOT;
! 27:
! 28: // different variations of associative arrays to be passed to $arr2 argument
! 29: $arrays = array (
! 30:
! 31: // empty array
! 32: /*1*/ array(),
! 33:
! 34: // arrays with integer keys
! 35: array(0 => "0"),
! 36: array(1 => "1"),
! 37: array(1 => "1", 2 => "2", 3 => "3", 4 => "4"),
! 38:
! 39: // arrays with float keys
! 40: /*5*/ array(2.3333 => "float"),
! 41: array(1.2 => "f1", 3.33 => "f2",
! 42: 4.89999922839999 => "f3",
! 43: 33333333.333333 => "f4"),
! 44:
! 45: // arrays with string keys
! 46: /*7*/ array('\tHello' => 111, 're\td' => "color",
! 47: '\v\fworld' => 2.2, 'pen\n' => 33),
! 48: array("\tHello" => 111, "re\td" => "color",
! 49: "\v\fworld" => 2.2, "pen\n" => 33),
! 50: array("hello", $heredoc => "string"), // heredoc
! 51:
! 52: // array with unset variable
! 53: /*10*/ array( @$unset_var => "hello"),
! 54:
! 55: // array with mixed keys
! 56: /*11*/ array('hello' => 1, "fruit" => 2.2,
! 57: 133 => "int", 444.432 => "float",
! 58: @$unset_var => "unset", $heredoc => "heredoc")
! 59: );
! 60:
! 61: // array to be passsed to $arr1 argument
! 62: $arr1 = array(0 => 0, 2 => "float", 4 => "f3", 33333333 => "f4",
! 63: "\tHello" => 111, 2.2, 'color', "Hello world" => "string",
! 64: "pen\n" => 33, 133 => "int");
! 65:
! 66: // loop through each sub-array within $arrrays to check the behavior of array_intersect_assoc()
! 67: $iterator = 1;
! 68: foreach($arrays as $arr2) {
! 69: echo "-- Iteration $iterator --\n";
! 70:
! 71: // Calling array_intersect_assoc() with default arguments
! 72: var_dump( array_intersect_assoc($arr1, $arr2) );
! 73:
! 74: // Calling array_intersect_assoc() with more arguments.
! 75: // additional argument passed is the same as $arr1 argument
! 76: var_dump( array_intersect_assoc($arr1, $arr2, $arr1) );
! 77: $iterator++;
! 78: }
! 79:
! 80: echo "Done";
! 81: ?>
! 82: --EXPECTF--
! 83: *** Testing array_intersect_assoc() : assoc array with diff keys to $arr2 argument ***
! 84: -- Iteration 1 --
! 85: array(0) {
! 86: }
! 87: array(0) {
! 88: }
! 89: -- Iteration 2 --
! 90: array(1) {
! 91: [0]=>
! 92: int(0)
! 93: }
! 94: array(1) {
! 95: [0]=>
! 96: int(0)
! 97: }
! 98: -- Iteration 3 --
! 99: array(0) {
! 100: }
! 101: array(0) {
! 102: }
! 103: -- Iteration 4 --
! 104: array(0) {
! 105: }
! 106: array(0) {
! 107: }
! 108: -- Iteration 5 --
! 109: array(1) {
! 110: [2]=>
! 111: string(5) "float"
! 112: }
! 113: array(1) {
! 114: [2]=>
! 115: string(5) "float"
! 116: }
! 117: -- Iteration 6 --
! 118: array(2) {
! 119: [4]=>
! 120: string(2) "f3"
! 121: [33333333]=>
! 122: string(2) "f4"
! 123: }
! 124: array(2) {
! 125: [4]=>
! 126: string(2) "f3"
! 127: [33333333]=>
! 128: string(2) "f4"
! 129: }
! 130: -- Iteration 7 --
! 131: array(0) {
! 132: }
! 133: array(0) {
! 134: }
! 135: -- Iteration 8 --
! 136: array(2) {
! 137: [" Hello"]=>
! 138: int(111)
! 139: ["pen
! 140: "]=>
! 141: int(33)
! 142: }
! 143: array(2) {
! 144: [" Hello"]=>
! 145: int(111)
! 146: ["pen
! 147: "]=>
! 148: int(33)
! 149: }
! 150: -- Iteration 9 --
! 151: array(1) {
! 152: ["Hello world"]=>
! 153: string(6) "string"
! 154: }
! 155: array(1) {
! 156: ["Hello world"]=>
! 157: string(6) "string"
! 158: }
! 159: -- Iteration 10 --
! 160: array(0) {
! 161: }
! 162: array(0) {
! 163: }
! 164: -- Iteration 11 --
! 165: array(1) {
! 166: [133]=>
! 167: string(3) "int"
! 168: }
! 169: array(1) {
! 170: [133]=>
! 171: string(3) "int"
! 172: }
! 173: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>