mirror of
https://github.com/php/doc-es.git
synced 2026-03-24 15:32:36 +01:00
231 lines
6.1 KiB
XML
231 lines
6.1 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: cd943f94a013b74df8765ab8e1a620a916a64a85 Maintainer: PhilDaiguille Status: ready -->
|
|
<!-- Reviewed: no -->
|
|
<!-- CREDITS: DavidA. -->
|
|
|
|
<refentry xml:id="function.array-slice" xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>array_slice</refname>
|
|
<refpurpose>Extrae una porción de 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> devuelve una serie de elementos
|
|
del array <parameter>array</parameter> comenzando en el
|
|
offset <parameter>offset</parameter> y representando
|
|
<parameter>length</parameter> elementos.
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>array</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
El array de entrada.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>offset</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Si <parameter>offset</parameter> es no negativo, la secuencia
|
|
comenzará en esta posición en el array <parameter>array</parameter>.
|
|
</para>
|
|
<para>
|
|
Si <parameter>offset</parameter> es negativo, la secuencia
|
|
comenzará en la posición <parameter>offset</parameter>, pero comenzando
|
|
desde el final del array <parameter>array</parameter>.
|
|
</para>
|
|
<note>
|
|
<para>
|
|
El parámetro <parameter>offset</parameter> indica la posición
|
|
en el array, no la clave.
|
|
</para>
|
|
</note>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>length</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Si <parameter>length</parameter> es proporcionado y positivo, entonces
|
|
la secuencia tendrá hasta ese número de elementos.
|
|
</para>
|
|
<para>
|
|
Si el array es más corto que <parameter>length</parameter>,
|
|
entonces solo los elementos del array disponibles estarán presentes.
|
|
</para>
|
|
<para>
|
|
Si <parameter>length</parameter> es proporcionado y negativo, entonces
|
|
la secuencia excluirá ese número de elementos del final del array.
|
|
</para>
|
|
<para>
|
|
Si es omitido, la secuencia tendrá todo
|
|
desde la posición <parameter>offset</parameter> hasta el final de
|
|
<parameter>array</parameter>.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>preserve_keys</parameter></term>
|
|
<listitem>
|
|
<note>
|
|
<para>
|
|
Por omisión <function>array_slice</function> reordenará y reinicializará
|
|
los índices enteros del array.
|
|
Este comportamiento puede ser modificado definiendo el parámetro
|
|
<parameter>preserve_keys</parameter> a &true;.
|
|
Las claves en forma de string son siempre conservadas,
|
|
independientemente de este parámetro.
|
|
</para>
|
|
</note>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
Devuelve la porción del array. Si la posición es mayor
|
|
que el tamaño del array, un array vacío es devuelto.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title>Ejemplo con <function>array_slice</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$input = array("a", "b", "c", "d", "e");
|
|
|
|
$output = array_slice($input, 2); // devuelve "c", "d", y "e"
|
|
$output = array_slice($input, -2, 1); // devuelve "d"
|
|
$output = array_slice($input, 0, 3); // devuelve "a", "b", y "c"
|
|
|
|
// note las claves de índice diferentes
|
|
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> y basado en un array</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> y array con claves mixtas</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
|
|
-->
|