mirror of
https://github.com/php/doc-es.git
synced 2026-03-24 07:22:16 +01:00
git-svn-id: https://svn.php.net/repository/phpdoc/es/trunk@311329 c90b9560-bf6c-de11-be94-00142212c4b1
246 lines
6.0 KiB
XML
246 lines
6.0 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: 0266c9027f8210bc596793d768b030723454d0f2 Maintainer: jpberdejo Status: ready -->
|
|
<!-- Reviewed: no -->
|
|
|
|
<refentry xml:id="function.array-merge" xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>array_merge</refname>
|
|
<refpurpose>Combina dos o más arrays</refpurpose>
|
|
</refnamediv>
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type>array</type><methodname>array_merge</methodname>
|
|
<methodparam><type>array</type><parameter>array1</parameter></methodparam>
|
|
<methodparam choice="opt"><type>array</type><parameter>...</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
Combina los elementos de uno o más arrays juntándolos de modo que los valores de
|
|
uno se anexan al final del anterior. Retorna el array
|
|
resultante.
|
|
</para>
|
|
<para>
|
|
Si los arrays de entrada tienen las mismas claves de string, entonces el valor más posterior para
|
|
esa clave sobrescribirá a la anterior. Sin embargo, los arrays que
|
|
contengan claves numéricas, el valor posterior <emphasis
|
|
role="strong">no</emphasis> sobrescribirá el valor original, sino que sera
|
|
adjuntado.
|
|
</para>
|
|
<para>
|
|
Los valores en el array de entrada con claves numéricas serán renumeradas con
|
|
claves incrementales comenzando desde cero en el array de resultado.
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>array1</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Array inicial para combinar.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>...</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Lista variable de arrays para combinar.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
Retorna el array resultante.
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="changelog">
|
|
&reftitle.changelog;
|
|
<para>
|
|
<informaltable>
|
|
<tgroup cols="2">
|
|
<thead>
|
|
<row>
|
|
<entry>&Version;</entry>
|
|
<entry>&Description;</entry>
|
|
</row>
|
|
</thead>
|
|
<tbody>
|
|
<row>
|
|
<entry>5.0.0</entry>
|
|
<entry>
|
|
<warning>
|
|
<para>
|
|
El comportamiento de <function>array_merge</function> fue modificado en PHP 5. A diferencia de PHP 4, <function>array_merge</function>
|
|
ahora sólo acepta parámetros de tipo <type>array</type>. Sin embargo, se puede utilizar typecasting
|
|
para combinar otros tipos. Véase el siguiente ejemplo para más detalles.
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>Ejemplo de <function>array_merge</function> de PHP 5</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$beginning = 'foo';
|
|
$end = array(1 => 'bar');
|
|
$result = array_merge((array)$beginning, (array)$end);
|
|
print_r($result);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen role="php">
|
|
<![CDATA[
|
|
Array
|
|
(
|
|
[0] => foo
|
|
[1] => bar
|
|
)
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
</warning>
|
|
</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title>Ejemplo de <function>array_merge</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$array1 = array("color" => "red", 2, 4);
|
|
$array2 = array("a", "b", "color" => "green", "shape" => "trapezoid", 4);
|
|
$result = array_merge($array1, $array2);
|
|
print_r($result);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen role="php">
|
|
<![CDATA[
|
|
Array
|
|
(
|
|
[color] => green
|
|
[0] => 2
|
|
[1] => 4
|
|
[2] => a
|
|
[3] => b
|
|
[shape] => trapezoid
|
|
[4] => 4
|
|
)
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>Ejemplo de <function>array_merge</function> simple</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$array1 = array();
|
|
$array2 = array(1 => "data");
|
|
$result = array_merge($array1, $array2);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
<para>
|
|
¡No se debe olvidar que las claves numéricas serán renumeradas!
|
|
</para>
|
|
<screen role="php">
|
|
<![CDATA[
|
|
Array
|
|
(
|
|
[0] => data
|
|
)
|
|
]]>
|
|
</screen>
|
|
<para>
|
|
Si se desean anexar elementos del segundo array al
|
|
primer array entretanto no se sobrescriban los elementos del primer
|
|
array y no se reindexe, utilizar el operador <literal>+</literal>
|
|
de unión de arrays.
|
|
</para>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$array1 = array(0 => 'zero_a', 2 => 'two_a', 3 => 'three_a');
|
|
$array2 = array(1 => 'one_b', 3 => 'three_b', 4 => 'four_b');
|
|
$result = $array1 + $array2;
|
|
var_dump($result);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
<para>
|
|
Las claves del primer array se preservaran. Si una clave
|
|
existe en ambos arrays, entonces el elemento del primer array
|
|
será usado y el elemento de la clave coincidente del segundo array
|
|
será ignorado.
|
|
</para>
|
|
<screen role="php">
|
|
<![CDATA[
|
|
array(5) {
|
|
[0]=>
|
|
string(6) "zero_a"
|
|
[2]=>
|
|
string(5) "two_a"
|
|
[3]=>
|
|
string(7) "three_a"
|
|
[1]=>
|
|
string(5) "one_b"
|
|
[4]=>
|
|
string(6) "four_b"
|
|
}
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><function>array_merge_recursive</function></member>
|
|
<member><function>array_combine</function></member>
|
|
<member><link linkend="language.operators.array">array operators</link></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
|
|
-->
|