1--TEST-- 2Test array_splice(): basic functionality 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 10echo "*** Testing array_splice() basic operations ***\n"; 11echo "test truncation \n"; 12$input = array("red", "green", "blue", "yellow"); 13var_dump (array_splice($input, 2)); 14var_dump ($input); 15// $input is now array("red", "green") 16 17echo "test removing entries from the middle \n"; 18$input = array("red", "green", "blue", "yellow"); 19var_dump (array_splice($input, 1, -1)); 20var_dump ($input); 21// $input is now array("red", "yellow") 22 23echo "test substitution at end \n"; 24$input = array("red", "green", "blue", "yellow"); 25var_dump (array_splice($input, 1, count($input), "orange")); 26var_dump ($input); 27// $input is now array("red", "orange") 28 29$input = array("red", "green", "blue", "yellow"); 30var_dump (array_splice($input, -1, 1, array("black", "maroon"))); 31var_dump ($input); 32// $input is now array("red", "green", 33// "blue", "black", "maroon") 34 35echo "test insertion \n"; 36$input = array("red", "green", "blue", "yellow"); 37var_dump (array_splice($input, 3, 0, "purple")); 38var_dump ($input); 39// $input is now array("red", "green", 40// "blue", "purple", "yellow"); 41 42 43?> 44--EXPECT-- 45*** Testing array_splice() basic operations *** 46test truncation 47array(2) { 48 [0]=> 49 string(4) "blue" 50 [1]=> 51 string(6) "yellow" 52} 53array(2) { 54 [0]=> 55 string(3) "red" 56 [1]=> 57 string(5) "green" 58} 59test removing entries from the middle 60array(2) { 61 [0]=> 62 string(5) "green" 63 [1]=> 64 string(4) "blue" 65} 66array(2) { 67 [0]=> 68 string(3) "red" 69 [1]=> 70 string(6) "yellow" 71} 72test substitution at end 73array(3) { 74 [0]=> 75 string(5) "green" 76 [1]=> 77 string(4) "blue" 78 [2]=> 79 string(6) "yellow" 80} 81array(2) { 82 [0]=> 83 string(3) "red" 84 [1]=> 85 string(6) "orange" 86} 87array(1) { 88 [0]=> 89 string(6) "yellow" 90} 91array(5) { 92 [0]=> 93 string(3) "red" 94 [1]=> 95 string(5) "green" 96 [2]=> 97 string(4) "blue" 98 [3]=> 99 string(5) "black" 100 [4]=> 101 string(6) "maroon" 102} 103test insertion 104array(0) { 105} 106array(5) { 107 [0]=> 108 string(3) "red" 109 [1]=> 110 string(5) "green" 111 [2]=> 112 string(4) "blue" 113 [3]=> 114 string(6) "purple" 115 [4]=> 116 string(6) "yellow" 117} 118