nlopess Wed Sep 15 14:27:52 2004 EDT
Modified files:
/phpdoc/en/reference/array/functions array-slice.xml
Log:
document preserve_keys
http://cvs.php.net/diff.php/phpdoc/en/reference/array/functions/array-slice.xml?r1=1.8&r2=1.9&ty=u
Index: phpdoc/en/reference/array/functions/array-slice.xml
diff -u phpdoc/en/reference/array/functions/array-slice.xml:1.8
phpdoc/en/reference/array/functions/array-slice.xml:1.9
--- phpdoc/en/reference/array/functions/array-slice.xml:1.8 Mon Dec 15 11:47:04
2003
+++ phpdoc/en/reference/array/functions/array-slice.xml Wed Sep 15 14:27:51 2004
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
-<!-- $Revision: 1.8 $ -->
+<!-- $Revision: 1.9 $ -->
<!-- splitted from ./en/functions/array.xml, last change in rev 1.2 -->
<refentry id="function.array-slice">
<refnamediv>
@@ -12,9 +12,8 @@
<type>array</type><methodname>array_slice</methodname>
<methodparam><type>array</type><parameter>array</parameter></methodparam>
<methodparam><type>int</type><parameter>offset</parameter></methodparam>
- <methodparam choice="opt"><type>int</type><parameter>
- length
- </parameter></methodparam>
+ <methodparam
choice="opt"><type>int</type><parameter>length</parameter></methodparam>
+ <methodparam
choice="opt"><type>bool</type><parameter>preserve_keys</parameter></methodparam>
</methodsynopsis>
<para>
<function>array_slice</function> returns the sequence of elements
@@ -38,9 +37,9 @@
<parameter>array</parameter>.
</para>
<para>
- Note that <function>array_slice</function> will ignore array
- keys, and will calculate offsets and lengths based on the
- actual positions of elements within the array.
+ Note that <function>array_slice</function> will reset the array keys by
+ default. Since PHP 5.0.2, you can change this behaviour by setting
+ <parameter>preserve_keys</parameter> to &true;.
</para>
<para>
<example>
@@ -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));
?>
]]>
</programlisting>
+ <para>
+ The above example will output:
+ </para>
+ <screen>
+<![CDATA[
+Array
+(
+ [0] => c
+ [1] => d
+)
+Array
+(
+ [2] => c
+ [3] => d
+)
+]]>
+ </screen>
</example>
</para>
<para>