mirror of
https://github.com/php/doc-es.git
synced 2026-03-25 16:02:13 +01:00
git-svn-id: https://svn.php.net/repository/phpdoc/es/trunk@180605 c90b9560-bf6c-de11-be94-00142212c4b1
180 lines
4.8 KiB
XML
180 lines
4.8 KiB
XML
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
<!-- $Revision: 1.5 $ -->
|
|
<!-- EN-Revision: 1.16 Maintainer: baoengb Status: ready -->
|
|
<!-- splitted from ./es/functions/array.xml, last change in rev 1.1 -->
|
|
<refentry id="function.array-merge">
|
|
<refnamediv>
|
|
<refname>array_merge</refname>
|
|
<refpurpose>Combina dos o más matrices</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Descripción</title>
|
|
<methodsynopsis>
|
|
<type>array</type><methodname>array_merge</methodname>
|
|
<methodparam><type>array</type><parameter>matriz1</parameter></methodparam>
|
|
<methodparam choice="opt"><type>array</type><parameter>matriz2</parameter></methodparam>
|
|
<methodparam choice="opt"><type>array</type><parameter> ...</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
<function>array_merge</function> combina los elementos de dos o
|
|
más matrices conjuntamente de modo que los valores de una son
|
|
agregados al final de los valores de la anterior. Devuelve la
|
|
matriz resultante.
|
|
</para>
|
|
<para>
|
|
Si las matrices de entrada tienen las mismas claves de cadena,
|
|
el último valor para cada clave reemplazará el valor previo de
|
|
la misma. Si, por el contrario, las matrices tienen la misma clave
|
|
numérica, esto no pasa y los valores son simplemente agregados.
|
|
</para>
|
|
<para>
|
|
Si sólo se da una matriz, y si tiene índices numéricos,
|
|
los índices son reacomodados. Para matrices asociativas, los
|
|
elementos duplicados se combinarán en el último. Vea
|
|
el ejemplo tres para más detalles.
|
|
</para>
|
|
<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>
|
|
<para>
|
|
El <varname>$result</varname> es:
|
|
</para>
|
|
<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 simple de <function>array_merge</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$array1 = array();
|
|
$array2 = array(1 => "data");
|
|
$result = array_merge($array1, $array2);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
<para>
|
|
No olvide que los índices numéricos serán reenumerados
|
|
</para>
|
|
<screen role="php">
|
|
<![CDATA[
|
|
Array
|
|
(
|
|
[0] => data
|
|
)
|
|
]]>
|
|
</screen>
|
|
<para>
|
|
Si quiere preservar completamente las matrices y solo quiere agregarlos
|
|
unos a otros, use el operador <literal>+</literal> :
|
|
</para>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$array1 = array();
|
|
$array2 = array(1 => "data");
|
|
$result = $array1 + $array2;
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
<para>
|
|
Los índices numéricos son preservados y por lo tanto
|
|
la asocuación permanece.
|
|
</para>
|
|
<screen role="php">
|
|
<![CDATA[
|
|
Array
|
|
(
|
|
[1] => data
|
|
)
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
<warning>
|
|
<para>
|
|
El comportamient de <function>array_merge</function> fue modificado en
|
|
PHP 5. A diferencia de PHP 4, la función <function>array_merge</function>
|
|
ahora acepta solo parámetros de tipo <type>array</type>. Sin
|
|
embargo, puede usar forzado de tipos para convertir otros tipos.
|
|
Vea el siguiente ejemplo para más detalles.
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>Ejemplo PHP 5 <function>array_merge</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$beginning = 'foo';
|
|
$end = array(1 => 'bar');
|
|
$result = array_merge((array)$beginning, (array)$end);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen role="php">
|
|
<![CDATA[
|
|
Array
|
|
(
|
|
[0] => foo
|
|
[1] => bar
|
|
)
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
</warning>
|
|
<para>
|
|
Vea también
|
|
<function>array_merge_recursive</function>,
|
|
<function>array_combine</function>,
|
|
<link linkend="language.operators.array">array operators</link>.
|
|
</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:"../../../../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
|
|
-->
|