2010-03-28 22:10:10 +00:00
|
|
|
<?xml version="1.0" encoding="utf-8"?>
|
2009-07-11 06:30:45 +00:00
|
|
|
<!-- $Revision$ -->
|
2007-06-20 22:25:43 +00:00
|
|
|
<refentry xml:id="function.array-slice" xmlns="http://docbook.org/ns/docbook">
|
2006-10-31 11:24:02 +00:00
|
|
|
<refnamediv>
|
|
|
|
<refname>array_slice</refname>
|
|
|
|
<refpurpose>Extract a slice of the array</refpurpose>
|
|
|
|
</refnamediv>
|
2007-12-30 19:17:05 +00:00
|
|
|
<refsect1 role="description">
|
|
|
|
&reftitle.description;
|
2006-10-31 11:24:02 +00:00
|
|
|
<methodsynopsis>
|
|
|
|
<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>
|
2009-01-16 16:14:26 +00:00
|
|
|
<methodparam choice="opt"><type>bool</type><parameter>preserve_keys</parameter><initializer>false</initializer></methodparam>
|
2006-10-31 11:24:02 +00:00
|
|
|
</methodsynopsis>
|
|
|
|
<para>
|
|
|
|
<function>array_slice</function> returns the sequence of elements
|
|
|
|
from the array <parameter>array</parameter> as specified by the
|
|
|
|
<parameter>offset</parameter> and <parameter>length</parameter>
|
|
|
|
parameters.
|
|
|
|
</para>
|
2009-11-14 20:20:34 +00:00
|
|
|
&array.resetspointer;
|
2007-12-30 19:17:05 +00:00
|
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
|
|
&reftitle.parameters;
|
2006-10-31 11:24:02 +00:00
|
|
|
<para>
|
2007-12-30 19:17:05 +00:00
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
|
|
|
<term><parameter>array</parameter></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The input array.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
|
|
|
<term><parameter>offset</parameter></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
If <parameter>offset</parameter> is non-negative, the sequence will
|
|
|
|
start at that offset in the <parameter>array</parameter>. If
|
|
|
|
<parameter>offset</parameter> is negative, the sequence will
|
|
|
|
start that far from the end of the <parameter>array</parameter>.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
|
|
|
<term><parameter>length</parameter></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
If <parameter>length</parameter> is given and is positive, then
|
|
|
|
the sequence will have that many elements in it. If
|
|
|
|
<parameter>length</parameter> is given and is negative then the
|
|
|
|
sequence will stop that many elements from the end of the
|
|
|
|
array. If it is omitted, then the sequence will have everything
|
|
|
|
from <parameter>offset</parameter> up until the end of the
|
|
|
|
<parameter>array</parameter>.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
|
|
|
<term><parameter>preserve_keys</parameter></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Note that <function>array_slice</function> will reorder and reset the
|
|
|
|
array indices by default. You can change this behaviour by setting
|
|
|
|
<parameter>preserve_keys</parameter> to &true;.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
</variablelist>
|
2006-10-31 11:24:02 +00:00
|
|
|
</para>
|
2007-12-30 19:17:05 +00:00
|
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
|
|
&reftitle.returnvalues;
|
2006-10-31 11:24:02 +00:00
|
|
|
<para>
|
2007-12-30 19:17:05 +00:00
|
|
|
Returns the slice.
|
2006-10-31 11:24:02 +00:00
|
|
|
</para>
|
2007-12-30 19:17:05 +00:00
|
|
|
</refsect1>
|
|
|
|
<refsect1 role="changelog">
|
|
|
|
&reftitle.changelog;
|
2006-10-31 11:24:02 +00:00
|
|
|
<para>
|
2007-12-30 19:17:05 +00:00
|
|
|
<informaltable>
|
|
|
|
<tgroup cols="2">
|
|
|
|
<thead>
|
|
|
|
<row>
|
|
|
|
<entry>&Version;</entry>
|
|
|
|
<entry>&Description;</entry>
|
|
|
|
</row>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
<row>
|
|
|
|
<entry>5.0.2</entry>
|
|
|
|
<entry>
|
|
|
|
The optional <parameter>preserve_keys</parameter> parameter was added.
|
|
|
|
</entry>
|
|
|
|
</row>
|
|
|
|
</tbody>
|
|
|
|
</tgroup>
|
|
|
|
</informaltable>
|
2006-10-31 11:24:02 +00:00
|
|
|
</para>
|
2007-12-30 19:17:05 +00:00
|
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
|
|
&reftitle.examples;
|
2006-10-31 11:24:02 +00:00
|
|
|
<para>
|
|
|
|
<example>
|
|
|
|
<title><function>array_slice</function> examples</title>
|
|
|
|
<programlisting role="php">
|
2002-04-15 00:12:54 +00:00
|
|
|
<![CDATA[
|
2003-05-30 18:12:53 +00:00
|
|
|
<?php
|
2003-12-15 16:55:22 +00:00
|
|
|
$input = array("a", "b", "c", "d", "e");
|
2002-04-15 00:12:54 +00:00
|
|
|
|
2003-08-17 12:21:03 +00:00
|
|
|
$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"
|
2004-09-15 18:27:51 +00:00
|
|
|
|
|
|
|
// note the differences in the array keys
|
|
|
|
print_r(array_slice($input, 2, -1));
|
|
|
|
print_r(array_slice($input, 2, -1, true));
|
2003-05-30 18:12:53 +00:00
|
|
|
?>
|
2002-04-15 00:12:54 +00:00
|
|
|
]]>
|
2006-10-31 11:24:02 +00:00
|
|
|
</programlisting>
|
|
|
|
&example.outputs;
|
|
|
|
<screen>
|
2004-09-15 18:27:51 +00:00
|
|
|
<![CDATA[
|
|
|
|
Array
|
|
|
|
(
|
|
|
|
[0] => c
|
|
|
|
[1] => d
|
|
|
|
)
|
|
|
|
Array
|
|
|
|
(
|
|
|
|
[2] => c
|
|
|
|
[3] => d
|
|
|
|
)
|
|
|
|
]]>
|
2006-10-31 11:24:02 +00:00
|
|
|
</screen>
|
|
|
|
</example>
|
|
|
|
</para>
|
2007-12-30 19:17:05 +00:00
|
|
|
</refsect1>
|
|
|
|
<refsect1 role="seealso">
|
|
|
|
&reftitle.seealso;
|
2006-10-31 11:24:02 +00:00
|
|
|
<para>
|
2007-12-30 19:17:05 +00:00
|
|
|
<simplelist>
|
|
|
|
<member><function>array_splice</function></member>
|
|
|
|
<member><function>unset</function></member>
|
|
|
|
</simplelist>
|
2006-10-31 11:24:02 +00:00
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
</refentry>
|
2002-04-15 00:12:54 +00:00
|
|
|
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
|
|
Local variables:
|
|
|
|
mode: sgml
|
|
|
|
sgml-omittag:t
|
|
|
|
sgml-shorttag:t
|
|
|
|
sgml-minimize-attributes:nil
|
|
|
|
sgml-always-quote-attributes:t
|
|
|
|
sgml-indent-step:1
|
|
|
|
sgml-indent-data:t
|
|
|
|
indent-tabs-mode:nil
|
|
|
|
sgml-parent-document:nil
|
2009-09-25 07:04:39 +00:00
|
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
2002-04-15 00:12:54 +00:00
|
|
|
sgml-exposed-tags:nil
|
|
|
|
sgml-local-catalogs:nil
|
|
|
|
sgml-local-ecat-files:nil
|
|
|
|
End:
|
|
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
|
|
vim: et tw=78 syn=sgml
|
|
|
|
vi: ts=1 sw=1
|
|
|
|
-->
|