array array_slice ( array $arr , int $start [, int $length = NULL [, bool $preserve_keys = false ]] )
引數說明:<?php $info = array(2=>"C語言中文網", 4=>"http://c.biancheng.net/", "PHP", "JavaScript", "Java", "Python", "C++"); //擷取得到 ["PHP", "JavaScript", "Java", "Python", "C++"] print_r( array_slice($info, 2) ); //擷取得到 ["JavaScript", "Java", "Python"] print_r( array_slice($info, -2, 3) ); //擷取得到 ["C語言中文網", "http://c.biancheng.net/", "PHP"] print_r( array_slice($info, 0, 3) ); //保留陣列的原始鍵名 print_r( array_slice($info, 0, 3, true) ); ?>執行以上程式的輸出結果為:
Array
(
[0] => PHP
[1] => JavaScript
[2] => Java
[3] => Python
[4] => C++
)
Array
(
[0] => Python
[1] => C++
)
Array
(
[0] => C語言中文網
[1] => http://c.biancheng.net/
[2] => PHP
)
Array
(
[2] => C語言中文網
[4] => http://c.biancheng.net/
[5] => PHP
)