File: array-slice.xml

package info (click to toggle)
php-doc 20061001-1
  • links: PTS
  • area: non-free
  • in suites: etch, etch-m68k
  • size: 45,764 kB
  • ctags: 1,611
  • sloc: xml: 502,485; php: 7,645; cpp: 500; makefile: 297; perl: 161; sh: 141; awk: 28
file content (105 lines) | stat: -rw-r--r-- 3,318 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.11 $ -->
<!-- splitted from ./en/functions/array.xml, last change in rev 1.2 -->
  <refentry id="function.array-slice">
   <refnamediv>
    <refname>array_slice</refname>
    <refpurpose>Extract a slice of the array</refpurpose>
   </refnamediv>
   <refsect1>
    <title>Description</title>
     <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>
      <methodparam choice="opt"><type>bool</type><parameter>preserve_keys</parameter></methodparam>
     </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>
    <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>
    <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>
    <para>
     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>
      <title><function>array_slice</function> examples</title>
      <programlisting role="php">
<![CDATA[
<?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));
?>
]]>
      </programlisting>
      &example.outputs;
      <screen>
<![CDATA[
Array
(
    [0] => c
    [1] => d
)
Array
(
    [2] => c
    [3] => d
)
]]>
      </screen>
     </example>
    </para>
    <para>
     See also <function>array_splice</function> and
     <function>unset</function>.
    </para>
   </refsect1>
  </refentry>

<!-- 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
sgml-default-dtd-file:"../../../../manual.ced"
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
-->