1--TEST-- 2Test 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 11echo "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]; 15var_dump (array_splice ($input_array[0],1,1)); 16var_dump ($input_array); 17 18echo "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]); 26var_dump (array_splice ($input_array,4,3)); 27var_dump ($input_array); 28 29echo "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); 35array_splice ($input_array,-1,1,$b); 36var_dump ($input_array); 37 38echo "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 44array_splice ($input_array,-1,1,$b); 45var_dump ($input_array); 46echo "Done\n"; 47?> 48--EXPECT-- 49test behaviour when input array is in a reference set 50array(1) { 51 [0]=> 52 int(2) 53} 54array(2) { 55 [0]=> 56 &array(1) { 57 [0]=> 58 int(1) 59 } 60 [1]=> 61 &array(1) { 62 [0]=> 63 int(1) 64 } 65} 66Test behaviour of input arrays containing references 67array(3) { 68 [0]=> 69 int(4) 70 [1]=> 71 &int(5) 72 ["six"]=> 73 &int(6) 74} 75array(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} 91Test behaviour of replacement array containing references 92array(4) { 93 [0]=> 94 int(0) 95 [1]=> 96 int(1) 97 [2]=> 98 &int(3) 99 [3]=> 100 &int(4) 101} 102Test behaviour of replacement which is part of reference set 103array(2) { 104 [0]=> 105 int(1) 106 [1]=> 107 int(3) 108} 109Done 110