mirror of
https://github.com/php/doc-fr.git
synced 2026-03-24 15:12:13 +01:00
237 lines
5.5 KiB
XML
237 lines
5.5 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: 9e0f03ac354d797d1d16c0fcc1663e5e170f2727 Maintainer: yannick Status: ready -->
|
|
<!-- Reviewed: no -->
|
|
|
|
<refentry xml:id="function.array-merge" xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>array_merge</refname>
|
|
<refpurpose>Fusionne plusieurs tableaux en un seul</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>
|
|
<function>array_merge</function> rassemble les éléments
|
|
d'un ou de plusieurs tableaux en ajoutant les valeurs
|
|
de l'un à la fin de l'autre. Le résultat est un tableau.
|
|
</para>
|
|
<para>
|
|
Si les tableaux d'entrées ont des clés en commun, alors,
|
|
la valeur finale pour cette clé écrasera la précédente. Cependant,
|
|
si les tableaux contiennent des clés numériques, la valeur
|
|
finale <emphasis role="strong">n'écrasera pas</emphasis> la valeur
|
|
originale, mais sera ajoutée.
|
|
</para>
|
|
<para>
|
|
Les clés numériques des tableaux d'entrées seront
|
|
renumérotées en clés incrémentées partant de zéro dans le tableau fusionné.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>arrays</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Liste de tableaux variable à fusionner.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
Retourne le tableau résultant.
|
|
Si appellé sans arguments, retourne un &array; vide.
|
|
</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>
|
|
Cette fonction peut désormais être appelée sans paramètres.
|
|
Auparavant, au moins un paramètre était requis.
|
|
</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title>Exemple avec <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>Exemple simple avec <function>array_merge</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$array1 = array();
|
|
$array2 = array(1 => "data");
|
|
$result = array_merge($array1, $array2);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
<para>
|
|
N'oubliez pas que les index numériques seront réindexés !
|
|
</para>
|
|
<screen role="php">
|
|
<![CDATA[
|
|
Array
|
|
(
|
|
[0] => data
|
|
)
|
|
]]>
|
|
</screen>
|
|
<para>
|
|
Si vous voulez ajouter des éléments du second tableau au premier
|
|
sans pour autant écraser ou ré-indexer les éléments du premier,
|
|
utilisez l'opérateur d'union <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>
|
|
Les clés du premier tableau sont préservées. Si une clé existe
|
|
dans les 2 tableaux, alors l'élément du premier sera utilisé
|
|
et la clé correspondante du second sera ignorée.
|
|
</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>Exemple avec <function>array_merge</function> avec des types non-tableaux</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>les <link linkend="language.operators.array">opérateurs de tableau</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
|
|
-->
|