$input = array ("red", "green", "blue", "yellow"); array_splice ($input, 2); / / $input is now array ("red", "green") $input = array ("red", "green", "blue", "yellow"); array_splice ($input, 1, -1); / / $input is now array ("red", "yellow") $input = array ("red", "green", "blue", "yellow"); array_splice ($input, 1, count($input), "orange"); / / $input is now array ("red", "orange") $input = array ("red", "green", "blue", "yellow"); array_splice ($input, -1, 1, array("black", "maroon")); / / $input is now array ("red", "green", / / "blue", "black", "maroon")
?php / / cas simple $input = array( "rouge", "vert", "bleu", "jaune"); array_splice($input, 2); / / $input est array("rouge", "vert") / / nombre d'éléments négatif $input = array("rouge", "vert", "bleu", "jaune"); array_splice($input, 1, -1); / / $input est array("rouge", "jaune") / / avec un élément de remplacement $input = array("rouge", "vert", "bleu", "jaune"); array_splice($input, 1, count($input), "orange"); / / $input est array("rouge", "orange") / / cas complexe $input = array("rouge", "vert", "bleu", "jaune"); array_splice($input, -1, 1, array("noir", "marron")); / / $input est array("rouge", "vert", / / "bleu", "noir", "marron")?