mirror of
https://github.com/php/doc-pt_br.git
synced 2026-03-23 22:52:12 +01:00
234 lines
5.5 KiB
XML
234 lines
5.5 KiB
XML
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!-- EN-Revision: 2e60c5134e7a847c99f81eb3f7ecee1f5efeeace Maintainer: leonardolara Status: ready --><!-- CREDITS: lucasr,felipe,ae,LPJFilho,leonardolara -->
|
|
<refentry xml:id="function.array-merge" xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>array_merge</refname>
|
|
<refpurpose>Combina um ou mais arrays</refpurpose>
|
|
</refnamediv>
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type>array</type><methodname>array_merge</methodname>
|
|
<methodparam rep="repeat"><type>array</type><parameter>arrays</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
Combina os elementos de dois ou mais arrays de forma que os elementos de um são
|
|
colocados no final do array anterior. Retorna o array resultante da
|
|
fusão.
|
|
</para>
|
|
<para>
|
|
Se os arrays dados têm as mesmas chaves string, então o último
|
|
valor para uma chave irá sobrescrever o valor anterior. Se, no entanto,
|
|
os arrays tem as mesmas chaves numéricas, o último valor para uma chave <emphasis
|
|
role="strong">não</emphasis> sobrescreverá o valor original, e sim adicionado ao array
|
|
resultante.
|
|
</para>
|
|
<para>
|
|
Se apenas um array é dado e o array é indexado numericamente,
|
|
as chaves são reindexadas de uma maneira contínua.
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>arrays</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Uma lista de arrays a combinar.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
Retorna o array resultante.
|
|
Se chamado sem argumentos, retorna um &array; vazio.
|
|
</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>7.4.0</entry>
|
|
<entry>
|
|
A função agora pode ser chamada sem argumentos.
|
|
Anteriormente, ao menos um parâmetro era necessário.
|
|
</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title>Exemplo de <function>array_merge</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$array1 = array("cor" => "vermelho", 2, 4);
|
|
$array2 = array("a", "b", "cor" => "verde", "forma" => "trapezoide", 4);
|
|
$result = array_merge($array1, $array2);
|
|
print_r($result);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen role="php">
|
|
<![CDATA[
|
|
Array
|
|
(
|
|
[cor] => verde
|
|
[0] => 2
|
|
[1] => 4
|
|
[2] => a
|
|
[3] => b
|
|
[forma] => trapezoide
|
|
[4] => 4
|
|
)
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>Exemplo simples de <function>array_merge</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$array1 = array();
|
|
$array2 = array(1 => "data");
|
|
$result = array_merge($array1, $array2);
|
|
print_r($result);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
<para>
|
|
Não esqueça que as chaves numéricas serão reordenadas!
|
|
</para>
|
|
<screen role="php">
|
|
<![CDATA[
|
|
Array
|
|
(
|
|
[0] => data
|
|
)
|
|
]]>
|
|
</screen>
|
|
<para>
|
|
Se a intenção for apenas adicionar os elementos do segundo array no
|
|
primeiro, sem sobrescrever os elementos e sem
|
|
causar a re-indexação, deve-se utilizar o operador
|
|
<literal>+</literal>:
|
|
</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>
|
|
As chaves do primeiro array são preservadas. Se uma chave
|
|
existir em dois arrays, então o elemento do primeiro array será
|
|
preservado e o elemento de mesma chave no segundo array será
|
|
descartado.
|
|
</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>
|
|
<para>
|
|
<example>
|
|
<title><function>array_merge</function> com tipos não array</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>
|
|
</refsect1>
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><function>array_merge_recursive</function></member>
|
|
<member><function>array_replace</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
|
|
-->
|