array array_splice ( array &$arr, int $start [, int $length = 0 [, mixed $replacement ]] )
引數說明:<?php $arr = array("red", "green", "blue", "yellow"); array_splice($arr, 2); print_r($arr); //$arr 現在變成 array("red", "green") $arr = array("red", "green", "blue", "yellow"); array_splice($arr, 1, -1); print_r($arr); //$arr 現在變成 array("red", "yellow") $arr = array("red", "green", "blue", "yellow"); array_splice($arr, 1, count($arr), "orange"); print_r($arr); //$arr 現在變成 array("red", "orange") $arr = array("red", "green", "blue", "yellow"); array_splice($arr, -1, 1, array("black", "maroon")); print_r($arr); //$input 現在變成 array("red", "green", "blue", "black", "maroon") $arr = array("red", "green", "blue", "yellow"); array_splice($arr, 3, 0, "purple"); print_r($arr); //$arr 現在變成 array("red", "green", "blue", "purple", "yellow"); ?>執行以上程式的輸出結果如下:
Array
(
[0] => red
[1] => green
)
Array
(
[0] => red
[1] => yellow
)
Array
(
[0] => red
[1] => orange
)
Array
(
[0] => red
[1] => green
[2] => blue
[3] => black
[4] => maroon
)
Array
(
[0] => red
[1] => green
[2] => blue
[3] => purple
[4] => yellow
)