| Source: lesson_05_i_array_merge.php | Résultat |
<?php $politiques = array("France_president" => "Chirac", "UK_premier_ministre" => "Blair", "Espagne_roi_" =>"Carlos"); $sportifs = array("Velo" => "Amstrong", "Foot" => "Cantona"); // On réunit les deux tableaux $célébrités = array_merge($politiques, $sportifs); echo "A l'origine : <br/>"; echo "<table border=1><tr><th>Valeur</th><th>Clé</th></tr>"; foreach($politiques as $maClé=>$maValeur) { echo "<tr><td>$maValeur</td><td>$maClé</td></tr>"; } echo "</table><br/>"; echo "<table border=1><tr><th>Valeur</th><th>Clé</th></tr>"; foreach($sportifs as $maClé=>$maValeur) { echo "<tr><td>$maValeur</td><td>$maClé</td></tr>"; } echo "</table><br/>"; echo "Apès merge : <br/>"; echo "<table border=1><tr><th>Valeur</th><th>Clé</th></tr>"; foreach($célébrités as $maClé=>$maValeur) { echo "<tr><td>$maValeur</td><td>$maClé</td></tr>"; } ?> </table>
| A l'origine :
| Valeur | Clé |
|---|
| Chirac | France_president | | Blair | UK_premier_ministre | | Carlos | Espagne_roi_ |
| Valeur | Clé |
|---|
| Amstrong | Velo | | Cantona | Foot |
Apès merge :
| Valeur | Clé |
|---|
| Chirac | France_president | | Blair | UK_premier_ministre | | Carlos | Espagne_roi_ | | Amstrong | Velo | | Cantona | Foot |
|