mirror of
https://github.com/php/doc-pt_br.git
synced 2026-03-23 22:52:12 +01:00
223 lines
5.8 KiB
XML
223 lines
5.8 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- EN-Revision: cd943f94a013b74df8765ab8e1a620a916a64a85 Maintainer: ae Status: ready --><!-- CREDITS: lucasr,felipe,ae,adiel,lhsazevedo -->
|
|
<refentry xml:id="function.array-slice" xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>array_slice</refname>
|
|
<refpurpose>Extrai uma parcela de um array</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> retorna a sequência de elementos
|
|
de um <parameter>array</parameter> delimitado pelos parâmetros
|
|
<parameter>offset</parameter> e <parameter>length</parameter>.
|
|
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>array</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
O array de entrada.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>offset</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Se <parameter>offset</parameter> for não negativo, a sequência iniciará
|
|
no início do <parameter>array</parameter>.
|
|
</para>
|
|
<para>
|
|
Se <parameter>offset</parameter> for negativo, a sequência iniciará
|
|
a partir do fim do <parameter>array</parameter>.
|
|
</para>
|
|
<note>
|
|
<para>
|
|
O parâmetro <parameter>offset</parameter> denota uma posição
|
|
dentro do array, não das chaves.
|
|
</para>
|
|
</note>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>length</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Se <parameter>length</parameter> for positivo,
|
|
então a sequência terá até essa quantidade de elementos.
|
|
</para>
|
|
<para>
|
|
Se o array for mais curto que <parameter>length</parameter>,
|
|
então somente os elementos presentes serão retornados.
|
|
</para>
|
|
<para>
|
|
Se <parameter>length</parameter> for negativo então a sequência
|
|
conterá até essa quantidade de elementos do final do array.
|
|
</para>
|
|
<para>
|
|
Se esse parâmetro for omitido, a sequência conterá todos os elementos
|
|
a partir de <parameter>offset</parameter> até o final do
|
|
<parameter>array</parameter>.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>preserve_keys</parameter></term>
|
|
<listitem>
|
|
<note>
|
|
<para>
|
|
<function>array_slice</function> não irá reordenar ou resetar os índices
|
|
inteiros do array por padrão. Este comportamento pode ser alterado
|
|
ao informar <parameter>preserve_keys</parameter> para &true;.
|
|
Chaves string são sempre preservados, independente do parâmetro.
|
|
</para>
|
|
</note>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
Retorna a parcela. Se o offset for maior que o tamanho do array,
|
|
um array vazio é retornado.
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title>Exemplos de <function>array_slice</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$input = array("a", "b", "c", "d", "e");
|
|
|
|
$output = array_slice($input, 2); // retorna "c", "d", e "e"
|
|
$output = array_slice($input, -2, 1); // retorna "d"
|
|
$output = array_slice($input, 0, 3); // retorna "a", "b", e "c"
|
|
|
|
// Obverse as diferenças nas chaves retornadas
|
|
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> e arrays baseados em 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> com chaves mistas</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$ar = array('a'=>'apple', 'b'=>'banana', '42'=>'pear', 'd'=>'orange');
|
|
print_r(array_slice($ar, 0, 3));
|
|
print_r(array_slice($ar, 0, 3, true));
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen>
|
|
<![CDATA[
|
|
Array
|
|
(
|
|
[a] => apple
|
|
[b] => banana
|
|
[0] => pear
|
|
)
|
|
Array
|
|
(
|
|
[a] => apple
|
|
[b] => banana
|
|
[42] => pear
|
|
)
|
|
]]>
|
|
</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
|
|
-->
|