Annotation of embedaddon/php/ext/standard/tests/array/array_unshift_variation6.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Test array_unshift() function : usage variations - two dimensional arrays for 'array' argument
! 3: --FILE--
! 4: <?php
! 5: /* Prototype : int array_unshift(array $array, mixed $var [, mixed ...])
! 6: * Description: Pushes elements onto the beginning of the array
! 7: * Source code: ext/standard/array.c
! 8: */
! 9:
! 10: /*
! 11: * Testing the functionality of array_unshift() by giving two-dimensional
! 12: * arrays and also sub-arrays within the two-dimensional array for $array argument.
! 13: * The $var argument passed is a fixed value
! 14: */
! 15:
! 16: echo "*** Testing array_unshift() : two dimensional arrays for \$array argument ***\n";
! 17:
! 18: // initializing $var argument
! 19: $var = 10;
! 20:
! 21: // two-dimensional array to be passed to $array argument
! 22: $two_dimensional_array = array(
! 23:
! 24: // associative array
! 25: array('color' => 'red', 'item' => 'pen', 'place' => 'LA'),
! 26:
! 27: // numeric array
! 28: array(1, 2, 3, 4, 5),
! 29:
! 30: // combination of numeric and associative arrays
! 31: array('a' => 'green', 'red', 'brown', 33, 88, 'orange', 'item' => 'ball')
! 32: );
! 33:
! 34: /* Passing the entire $two_dimensional_array to $array */
! 35:
! 36: /* With default argument */
! 37: // returns element count in the resulting array after arguments are pushed to
! 38: // beginning of the given array
! 39: $temp_array = $two_dimensional_array;
! 40: var_dump( array_unshift($temp_array, $var) ); // whole 2-d array
! 41:
! 42: // dumps the resulting array
! 43: var_dump($temp_array);
! 44:
! 45: /* With optional arguments */
! 46: // returns element count in the resulting array after arguments are pushed to
! 47: // beginning of the given array
! 48: $temp_array = $two_dimensional_array;
! 49: var_dump( array_unshift($temp_array, $var, "hello", 'world') ); // whole 2-d array
! 50:
! 51: // dumps the resulting array
! 52: var_dump($temp_array);
! 53:
! 54: /* Passing the sub-array within the $two_dimensional_array to $array argument */
! 55:
! 56: /* With default argument */
! 57: // returns element count in the resulting array after arguments are pushed to
! 58: // beginning of the given array
! 59: $temp_array = $two_dimensional_array[0];
! 60: var_dump( array_unshift($temp_array, $var) ); // sub array
! 61:
! 62: // dumps the resulting array
! 63: var_dump($temp_array);
! 64:
! 65: /* With optional arguments */
! 66: // returns element count in the resulting array after arguments are pushed to
! 67: // beginning of the given array
! 68: $temp_array = $two_dimensional_array[0];
! 69: var_dump( array_unshift($temp_array, $var, "hello", 'world') ); // sub array
! 70:
! 71: // dumps the resulting array
! 72: var_dump($temp_array);
! 73:
! 74: echo "Done";
! 75: ?>
! 76: --EXPECTF--
! 77: *** Testing array_unshift() : two dimensional arrays for $array argument ***
! 78: int(4)
! 79: array(4) {
! 80: [0]=>
! 81: int(10)
! 82: [1]=>
! 83: array(3) {
! 84: ["color"]=>
! 85: string(3) "red"
! 86: ["item"]=>
! 87: string(3) "pen"
! 88: ["place"]=>
! 89: string(2) "LA"
! 90: }
! 91: [2]=>
! 92: array(5) {
! 93: [0]=>
! 94: int(1)
! 95: [1]=>
! 96: int(2)
! 97: [2]=>
! 98: int(3)
! 99: [3]=>
! 100: int(4)
! 101: [4]=>
! 102: int(5)
! 103: }
! 104: [3]=>
! 105: array(7) {
! 106: ["a"]=>
! 107: string(5) "green"
! 108: [0]=>
! 109: string(3) "red"
! 110: [1]=>
! 111: string(5) "brown"
! 112: [2]=>
! 113: int(33)
! 114: [3]=>
! 115: int(88)
! 116: [4]=>
! 117: string(6) "orange"
! 118: ["item"]=>
! 119: string(4) "ball"
! 120: }
! 121: }
! 122: int(6)
! 123: array(6) {
! 124: [0]=>
! 125: int(10)
! 126: [1]=>
! 127: string(5) "hello"
! 128: [2]=>
! 129: string(5) "world"
! 130: [3]=>
! 131: array(3) {
! 132: ["color"]=>
! 133: string(3) "red"
! 134: ["item"]=>
! 135: string(3) "pen"
! 136: ["place"]=>
! 137: string(2) "LA"
! 138: }
! 139: [4]=>
! 140: array(5) {
! 141: [0]=>
! 142: int(1)
! 143: [1]=>
! 144: int(2)
! 145: [2]=>
! 146: int(3)
! 147: [3]=>
! 148: int(4)
! 149: [4]=>
! 150: int(5)
! 151: }
! 152: [5]=>
! 153: array(7) {
! 154: ["a"]=>
! 155: string(5) "green"
! 156: [0]=>
! 157: string(3) "red"
! 158: [1]=>
! 159: string(5) "brown"
! 160: [2]=>
! 161: int(33)
! 162: [3]=>
! 163: int(88)
! 164: [4]=>
! 165: string(6) "orange"
! 166: ["item"]=>
! 167: string(4) "ball"
! 168: }
! 169: }
! 170: int(4)
! 171: array(4) {
! 172: [0]=>
! 173: int(10)
! 174: ["color"]=>
! 175: string(3) "red"
! 176: ["item"]=>
! 177: string(3) "pen"
! 178: ["place"]=>
! 179: string(2) "LA"
! 180: }
! 181: int(6)
! 182: array(6) {
! 183: [0]=>
! 184: int(10)
! 185: [1]=>
! 186: string(5) "hello"
! 187: [2]=>
! 188: string(5) "world"
! 189: ["color"]=>
! 190: string(3) "red"
! 191: ["item"]=>
! 192: string(3) "pen"
! 193: ["place"]=>
! 194: string(2) "LA"
! 195: }
! 196: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>