mirror of
https://github.com/php/doc-pl.git
synced 2026-03-24 07:02:07 +01:00
224 lines
6.1 KiB
XML
224 lines
6.1 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- EN-Revision: cd943f94a013b74df8765ab8e1a620a916a64a85 Maintainer: leszek Status: ready -->
|
|
<!-- $Revision$ -->
|
|
<refentry xml:id="function.array-slice" xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>array_slice</refname>
|
|
<refpurpose>Wycina kawałek tablicy</refpurpose>
|
|
</refnamediv>
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<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 class="union"><type>int</type><type>null</type></type><parameter>length</parameter><initializer>&null;</initializer></methodparam>
|
|
<methodparam choice="opt"><type>bool</type><parameter>preserve_keys</parameter><initializer>&false;</initializer></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
<function>array_slice</function> zwraca sekwencję elementów
|
|
z tablicy <parameter>array</parameter> zaczynającą się od parametru
|
|
<parameter>offset</parameter> i długości <parameter>length</parameter>.
|
|
parameters.
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>array</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Tablica wejściowa.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>offset</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Jeżeli parametr <parameter>offset</parameter> nie jest ujemny, sekwencja
|
|
zacznie się na podanym przesunięciu w tablicy <parameter>array</parameter>.
|
|
</para>
|
|
<para>
|
|
Jeżeli parametr <parameter>offset</parameter> jest ujemny, sekwencja
|
|
rozpocznie się od końca tablicy <parameter>array</parameter>.
|
|
</para>
|
|
<note>
|
|
<para>
|
|
Parametr <parameter>offset</parameter> określa pozycję
|
|
w tablicy, a nie klucz.
|
|
</para>
|
|
</note>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>length</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Jeżeli podano parametr <parameter>length</parameter> i jest on dodatni,
|
|
to sekwencja będzie miała maksymalnie tyle elementów, ile podano.
|
|
</para>
|
|
<para>
|
|
Jeżeli tablica jest mniejsza niż parametr <parameter>length</parameter>,
|
|
to zostaną zwrócone tylko dostępne elementy tablicy.
|
|
</para>
|
|
<para>
|
|
Jeżeli podano ujemny parametr <parameter>length</parameter>, to
|
|
sekwencja zakończy się na tylu elementach, ile w nim podano, licząc od końca tablicy.
|
|
</para>
|
|
<para>
|
|
Jeżeli ten parametr zostanie pominięty, to sekwencja będzie zawierała
|
|
wszystkie elementy począwszy od <parameter>offset</parameter> aż do samego
|
|
końca tablicy <parameter>array</parameter>.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>preserve_keys</parameter></term>
|
|
<listitem>
|
|
<note>
|
|
<para>
|
|
<function>array_slice</function> domyślnie przenumerowuje i resetuje numeryczne
|
|
klucze tablicy. Można zmienić to zachowanie
|
|
ustawiając <parameter>preserve_keys</parameter> na &true;.
|
|
Klucze będące ciągami znaków są zawsze zachowywane, niezależnie od tego parametru.
|
|
</para>
|
|
</note>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
Zwraca wycinek tablicy. Jeżeli podane przesunięcie jest większe niż wycinek tablicy,
|
|
to zwrócona zostanie pusta tablica.
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title>Przykłady użycia <function>array_slice</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$input = array("a", "b", "c", "d", "e");
|
|
|
|
$output = array_slice($input, 2); // zwraca "c", "d", and "e"
|
|
$output = array_slice($input, -2, 1); // zwraca "d"
|
|
$output = array_slice($input, 0, 3); // zwraca "a", "b", and "c"
|
|
|
|
// zwróć uwagę na różnicę w kluczach tablicy
|
|
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>
|
|
<example>
|
|
<title><function>array_slice</function> i tablica rozpoczynająca się od 1</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$input = array(1 => "a", "b", "c", "d", "e");
|
|
print_r(array_slice($input, 1, 2));
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen>
|
|
<![CDATA[
|
|
Array
|
|
(
|
|
[0] => b
|
|
[1] => c
|
|
)
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title><function>array_slice</function> i tablica z mieszanymi kluczami</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$ar = array('a'=>'jabłko', 'b'=>'banan', '42'=>'gruszka', 'd'=>'pomarańcza');
|
|
print_r(array_slice($ar, 0, 3));
|
|
print_r(array_slice($ar, 0, 3, true));
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen>
|
|
<![CDATA[
|
|
Array
|
|
(
|
|
[a] => jabłko
|
|
[b] => banan
|
|
[0] => gruszka
|
|
)
|
|
Array
|
|
(
|
|
[a] => jabłko
|
|
[b] => banan
|
|
[42] => gruszka
|
|
)
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><function>array_chunk</function></member>
|
|
<member><function>array_splice</function></member>
|
|
<member><function>unset</function></member>
|
|
</simplelist>
|
|
</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
|
|
-->
|