From b3ff644c6c6c6dd0f6bfd99924df16f362da2374 Mon Sep 17 00:00:00 2001 From: Nuno Lopes Date: Wed, 15 Sep 2004 18:27:51 +0000 Subject: [PATCH] document preserve_keys git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@168647 c90b9560-bf6c-de11-be94-00142212c4b1 --- reference/array/functions/array-slice.xml | 35 +++++++++++++++++------ 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/reference/array/functions/array-slice.xml b/reference/array/functions/array-slice.xml index 38ef66c355..60e0be2fb9 100644 --- a/reference/array/functions/array-slice.xml +++ b/reference/array/functions/array-slice.xml @@ -1,5 +1,5 @@ - + @@ -12,9 +12,8 @@ arrayarray_slice arrayarray intoffset - int - length - + intlength + boolpreserve_keys array_slice returns the sequence of elements @@ -38,9 +37,9 @@ array. - Note that array_slice will ignore array - keys, and will calculate offsets and lengths based on the - actual positions of elements within the array. + Note that array_slice will reset the array keys by + default. Since PHP 5.0.2, you can change this behaviour by setting + preserve_keys to &true;. @@ -51,12 +50,32 @@ $input = array("a", "b", "c", "d", "e"); $output = array_slice($input, 2); // returns "c", "d", and "e" -$output = array_slice($input, 2, -1); // returns "c", "d" $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)); ?> ]]> + + The above example will output: + + + c + [1] => d +) +Array +( + [2] => c + [3] => d +) +]]> +