mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
document preserve_keys
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@168647 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
7ab58d735c
commit
b3ff644c6c
1 changed files with 27 additions and 8 deletions
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue