1
0
mirror of https://github.com/php/doc-ru.git synced 2026-04-27 17:23:32 +02:00
Files
archived-doc-ru/reference/array/functions/array-slice.xml
T
2005-03-06 16:44:36 +00:00

108 lines
4.4 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- EN-Revision: 1.9 Maintainer: sveta Status: ready -->
<!-- $Revision: 1.2 $ -->
<!-- splitted from ./en/functions/array.xml, last change in rev 1.2 -->
<refentry id="function.array-slice">
<refnamediv>
<refname>array_slice</refname>
<refpurpose>Выбрать срез массива</refpurpose>
</refnamediv>
<refsect1>
<title>Описание</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> возвращает последовательность
элементов массива <parameter>array</parameter>, определённую параметрами
<parameter>offset</parameter> и <parameter>length</parameter>.
</para>
<para>
Если параметр <parameter>offset</parameter> положителен, последовательность
начнётся на расстоянии offset от начала <parameter>array</parameter>. Если
<parameter>offset</parameter> отрицателен, последовательность
начнётся на расстоянии offset от конца <parameter>array</parameter>.
</para>
<para>
Если в эту функцию передан положительный параметр <parameter>length</parameter>,
последовательность будет включать length элементов.
Если в эту функцию передан отрицательный параметр <parameter>length</parameter>,
в последовательность войдут все элементы исходного массива, начиная с позиции <parameter>offset</parameter>
и заканчивая позицией, отстоящей на <parameter>length</parameter> элементов от конца <parameter>array</parameter>.
Если этот параметр будет опущен, в последовательность войдут все элементы
исходного массива <parameter>array</parameter>, начиная с позиции <parameter>offset</parameter>.
</para>
<para>
Обратите внимание, что <function>array_slice</function> сбрасывает ключи массива.
Начиная с PHP 5.0.2 вы можете переопределить это поведение, установив параметр
<parameter>preserve_keys</parameter> в &true;.
</para>
<para>
<example>
<title>Пример использования <function>array_slice</function></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>
<para>
Вышеприведённый пример выведет:
</para>
<screen>
<![CDATA[
Array
(
[0] => c
[1] => d
)
Array
(
[2] => c
[3] => d
)
]]>
</screen>
</example>
</para>
<para>
См. также <function>array_splice</function> и
<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
-->