(PHP 4, PHP 5, PHP 7)
array_slice — ��������ȡ��һ��
$array
, int $offset
[, int $length = NULL
[, bool $preserve_keys = false
]] ) : array
array_slice() ���ظ��� offset ��
length ������ָ���� array
�����е�һ�����С�
array��������顣
offset
��� offset �Ǹ��������н��� array
�еĴ�ƫ������ʼ����� offset Ϊ���������н���
array �о���ĩ����ôԶ�ĵط���ʼ��
length
��������� length ����Ϊ�����������н�������ô��ĵ�Ԫ�����������
length ����Ϊ���������н���ֹ�ھ�������ĩ����ôԶ�ĵط������ʡ�ԣ������н���
offset ��ʼһֱ�� array ��ĩ�ˡ�
preserve_keys
ע�� array_slice() Ĭ�ϻ���������������������������������ͨ����
preserve_keys ��Ϊ TRUE ���ı����Ϊ��
��������һ�Ρ� ��� offset �������� array �ߴ磬�ͻ᷵�ؿյ� array��
| �汾 | ˵�� |
|---|---|
| 5.2.4 |
length ����Ĭ��ֵ�ij� NULL��
���� length Ϊ NULL ʱ����˼��˵ʹ�� array �ij��ȡ�
֮ǰ�İ汾� NULL �� length
����˼�dz���Ϊ�㣨ɶҲ�����أ���
|
| 5.0.2 |
�����˿�ѡ���� preserve_keys ��
|
Example #1 array_slice() ����
<?php
$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"
// note the differences in the array keys
print_r(array_slice($input, 2, -1));
print_r(array_slice($input, 2, -1, true));
?>
�������̻������
Array
(
[0] => c
[1] => d
)
Array
(
[2] => c
[3] => d
)