mirror of
https://github.com/php/doc-es.git
synced 2026-03-24 07:22:16 +01:00
282 lines
7.9 KiB
XML
282 lines
7.9 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- EN-Revision: 2e60c5134e7a847c99f81eb3f7ecee1f5efeeace Maintainer: PhilDaiguille Status: ready -->
|
|
<!-- Reviewed: no -->
|
|
<!-- CREDITS: DavidA. -->
|
|
<refentry xml:id="function.array-splice" xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>array_splice</refname>
|
|
<refpurpose>Elimina y reemplaza una porción de array</refpurpose>
|
|
</refnamediv>
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type>array</type><methodname>array_splice</methodname>
|
|
<methodparam><type>array</type><parameter role="reference">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>mixed</type><parameter>replacement</parameter><initializer>[]</initializer></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
<function>array_splice</function> elimina los elementos
|
|
designados por <parameter>offset</parameter> y
|
|
<parameter>length</parameter> del array <parameter>array</parameter> y
|
|
los reemplaza por los elementos del array
|
|
<parameter>replacement</parameter>, si este último es proporcionado.
|
|
</para>
|
|
<note>
|
|
<para>
|
|
Las claves numéricas en <parameter>array</parameter> no son preservadas.
|
|
</para>
|
|
</note>
|
|
<note>
|
|
<simpara>
|
|
Si <parameter>replacement</parameter> no es un array, se convertirá en uno por <link linkend="language.types.array.casting">conversión</link>
|
|
(i.e. <code>(array) $replacement</code>). Esto puede producir resultados inesperados al utilizar un objeto o &null; como
|
|
argumento <parameter>replacement</parameter>.
|
|
</simpara>
|
|
</note>
|
|
</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 positivo, el inicio de la sección
|
|
a eliminar estará en esta posición partiendo del inicio del array
|
|
<parameter>array</parameter>.
|
|
</para>
|
|
<para>
|
|
Si <parameter>offset</parameter> es negativo, el inicio de la sección
|
|
a eliminar estará en esta posición partiendo del final del array
|
|
<parameter>array</parameter>.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>length</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Si <parameter>length</parameter> es omitido, todos los elementos del array
|
|
desde la posición <parameter>offset</parameter> hasta el final del
|
|
array serán eliminados.
|
|
</para>
|
|
<para>
|
|
Si <parameter>length</parameter> es proporcionado y positivo,
|
|
entonces tantos elementos serán eliminados.
|
|
</para>
|
|
<para>
|
|
Si <parameter>length</parameter> es proporcionado y negativo,
|
|
entonces tantos elementos serán eliminados del final del array.
|
|
</para>
|
|
<para>
|
|
Si <parameter>length</parameter> es proporcionado y vale cero,
|
|
entonces ningún elemento será eliminado.
|
|
</para>
|
|
<tip>
|
|
<para>
|
|
Para eliminar todo desde la posición <parameter>offset</parameter>
|
|
hasta el final del array cuando <parameter>replacement</parameter>
|
|
también es proporcionado, utilizar <code>count($input)</code> para <parameter>length</parameter>.
|
|
</para>
|
|
</tip>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>replacement</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Si el &array; <parameter>replacement</parameter> es proporcionado, entonces los
|
|
elementos eliminados son reemplazados por los elementos de este &array;.
|
|
</para>
|
|
<para>
|
|
Si el <parameter>offset</parameter> y <parameter>length</parameter>
|
|
son tales que nada es eliminado, entonces los elementos del &array;
|
|
<parameter>replacement</parameter> son insertados en la posición
|
|
<parameter>offset</parameter>.
|
|
</para>
|
|
<note>
|
|
<para>
|
|
Las claves del &array; <parameter>replacement</parameter> no son preservadas.
|
|
</para>
|
|
</note>
|
|
<para>
|
|
Si <parameter>replacement</parameter> es solo un elemento no es necesario
|
|
rodear el elemento con <literal>array()</literal> o corchetes,
|
|
a menos que el elemento sea él mismo un array, un objeto o &null;.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
Retorna un &array; conteniendo los elementos extraídos.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="changelog">
|
|
&reftitle.changelog;
|
|
<informaltable>
|
|
<tgroup cols="2">
|
|
<thead>
|
|
<row>
|
|
<entry>&Version;</entry>
|
|
<entry>&Description;</entry>
|
|
</row>
|
|
</thead>
|
|
<tbody>
|
|
<row>
|
|
<entry>8.0.0</entry>
|
|
<entry>
|
|
<parameter>length</parameter> ahora es nullable.
|
|
</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title>Ejemplos con <function>array_splice</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$input = array("red", "green", "blue", "yellow");
|
|
array_splice($input, 2);
|
|
var_dump($input);
|
|
|
|
$input = array("red", "green", "blue", "yellow");
|
|
array_splice($input, 1, -1);
|
|
var_dump($input);
|
|
|
|
$input = array("red", "green", "blue", "yellow");
|
|
array_splice($input, 1, count($input), "orange");
|
|
var_dump($input);
|
|
|
|
$input = array("red", "green", "blue", "yellow");
|
|
array_splice($input, -1, 1, array("black", "maroon"));
|
|
var_dump($input);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen>
|
|
<![CDATA[
|
|
array(2) {
|
|
[0]=>
|
|
string(3) "red"
|
|
[1]=>
|
|
string(5) "green"
|
|
}
|
|
array(2) {
|
|
[0]=>
|
|
string(3) "red"
|
|
[1]=>
|
|
string(6) "yellow"
|
|
}
|
|
array(2) {
|
|
[0]=>
|
|
string(3) "red"
|
|
[1]=>
|
|
string(6) "orange"
|
|
}
|
|
array(5) {
|
|
[0]=>
|
|
string(3) "red"
|
|
[1]=>
|
|
string(5) "green"
|
|
[2]=>
|
|
string(4) "blue"
|
|
[3]=>
|
|
string(5) "black"
|
|
[4]=>
|
|
string(6) "maroon"
|
|
}
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>Declaraciones equivalentes a ejemplos de <function>array_splice</function> diversos</title>
|
|
<para>
|
|
Las declaraciones siguientes son equivalentes:
|
|
</para>
|
|
<programlisting role="php" annotations="non-interactive">
|
|
<![CDATA[
|
|
<?php
|
|
|
|
// añadir dos elementos a $input
|
|
array_push($input, $x, $y);
|
|
array_splice($input, count($input), 0, array($x, $y));
|
|
|
|
// eliminar el último elemento de $input
|
|
array_pop($input);
|
|
array_splice($input, -1);
|
|
|
|
// eliminar el primer elemento de $input
|
|
array_shift($input);
|
|
array_splice($input, 0, 1);
|
|
|
|
// insertar dos elementos al inicio de $input
|
|
array_unshift($input, $x, $y);
|
|
array_splice($input, 0, 0, array($x, $y));
|
|
|
|
// reemplazar el valor en $input en el índice $x
|
|
$input[$x] = $y; // para arrays donde las claves son iguales al offset
|
|
array_splice($input, $x, 1, $y);
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><function>array_merge</function></member>
|
|
<member><function>array_slice</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
|
|
-->
|