Return to array_splice_variation1.phpt CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / standard / tests / array |
1.1 misho 1: --TEST-- 2: Test array_splice() function : usage variations - references 3: --FILE-- 4: <?php 5: /* 6: * proto array array_splice(array input, int offset [, int length [, array replacement]]) 7: * Function is implemented in ext/standard/array.c 8: */ 9: 10: 11: echo "test behaviour when input array is in a reference set\n"; 12: 13: $input_array=array (array(1,2)); 14: $input_array[]=&$input_array[0]; 15: var_dump (array_splice ($input_array[0],1,1)); 16: var_dump ($input_array); 17: 18: echo "Test behaviour of input arrays containing references \n"; 19: /* 20: * There are three regions to test:, before cut, the cut and after the cut. 21: * For reach we check a plain value, a reference value with integer key and a 22: * reference value with a string key. 23: */ 24: $numbers=array(0,1,2,3,4,5,6,7,8,9,10,11,12); 25: $input_array=array(0,1,&$numbers[2],"three"=>&$numbers[3],4,&$numbers[5],"six"=>&$numbers[6],7,&$numbers[8],"nine"=>&$numbers[9]); 26: var_dump (array_splice ($input_array,4,3)); 27: var_dump ($input_array); 28: 29: echo "Test behaviour of replacement array containing references \n"; 30: 31: $three=3; 32: $four=4; 33: $input_array=array (0,1,2); 34: $b=array(&$three,"fourkey"=>&$four); 35: array_splice ($input_array,-1,1,$b); 36: var_dump ($input_array); 37: 38: echo "Test behaviour of replacement which is part of reference set \n"; 39: 40: $int=3; 41: $input_array=array (1,2); 42: $b=&$int; 43: 44: array_splice ($input_array,-1,1,$b); 45: var_dump ($input_array); 46: echo "Done\n"; 47: ?> 48: --EXPECT-- 49: test behaviour when input array is in a reference set 50: array(1) { 51: [0]=> 52: int(2) 53: } 54: array(2) { 55: [0]=> 56: &array(1) { 57: [0]=> 58: int(1) 59: } 60: [1]=> 61: &array(1) { 62: [0]=> 63: int(1) 64: } 65: } 66: Test behaviour of input arrays containing references 67: array(3) { 68: [0]=> 69: int(4) 70: [1]=> 71: &int(5) 72: ["six"]=> 73: &int(6) 74: } 75: array(7) { 76: [0]=> 77: int(0) 78: [1]=> 79: int(1) 80: [2]=> 81: &int(2) 82: ["three"]=> 83: &int(3) 84: [3]=> 85: int(7) 86: [4]=> 87: &int(8) 88: ["nine"]=> 89: &int(9) 90: } 91: Test behaviour of replacement array containing references 92: array(4) { 93: [0]=> 94: int(0) 95: [1]=> 96: int(1) 97: [2]=> 98: &int(3) 99: [3]=> 100: &int(4) 101: } 102: Test behaviour of replacement which is part of reference set 103: array(2) { 104: [0]=> 105: int(1) 106: [1]=> 107: int(3) 108: } 109: Done