Files
php-doc-ru/reference/array/functions/array-slice.xml
Shein Alexey ab3c2130fa Fixed path to sgml-default-dtd-file.
git-svn-id: https://svn.php.net/repository/phpdoc/ru/trunk@305403 c90b9560-bf6c-de11-be94-00142212c4b1
2010-11-16 08:52:05 +00:00

108 lines
4.3 KiB
XML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?xml version="1.0" encoding="utf-8"?>
<!-- EN-Revision: n/a Maintainer: sveta Status: ready -->
<!-- $Revision$ -->
<!-- splitted from ./en/functions/array.xml, last change in rev 1.2 -->
<refentry xml:id="function.array-slice" xmlns="http://docbook.org/ns/docbook">
<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:"../~/.phpdoc/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
-->