ตัวอย่าง code
โค้ด: เลือกทั้งหมด
$input = array("a", "b", "c", "d", "e");
$output = array_slice($input, 2); // returns "c", "d", and "e"
$output = array_slice($input, -2, 1); // returns "d"
$output = array_slice($input, 0, 3); // returns "a", "b", and "c"
โค้ด: เลือกทั้งหมด
$test = array(
1=>'hello 1',
2=>'hello 2',
3=>'hello 3',
4=>'hello 4',
5=>'hello 5',
6=>'hello 6',
7=>'hello 7',
8=>'hello 8'
);
print_r( array_slice($test,2,5) );
โค้ด: เลือกทั้งหมด
Array
(
[0] => hello 3
[1] => hello 4
[2] => hello 5
[3] => hello 6
[4] => hello 7
)
ที่มา : http://php.net/manual/en/function.array-slice.php