NOVINKA: Kurz kybernetickej bezpečnosti teraz už od 0 €. Staň sa žiadaným profesionálom. Zisti viac:
NOVINKA: Staň sa dátovým analytikom od 0 € a získaj istotu práce, lepší plat a nové kariérne možnosti. Viac informácií:

PHP - array_merge

Trieda

Koreň \ Bez triedy

Metóda - array_merge

(PHP 4, PHP 5, PHP 7)

The function merges several arrays into one array. The result array is created by appending the array to the end of the previous one. If the key exists in the array, it will be replaced. If we only merge arrays with numerical indexes, they are not replaced, but they are simply put one by one where the result array is renumbered from zero.

Procedurálne

  • function array_merge (array $array1, array $...) : array

Parametre

NázovDátový typPredvolená hodnotaPopis
$array1array

An array.

$...array

Several arrays.

Mávratovej hodnoty

Vracia: array

An array made by merging several arrays.

Príklady

Firstly, we merge simple, numerically-indexed arrays:

<?php
$a = [1, 2, 3];
$b = [4, 5, 6];
$c = [7, 8, 9];
$array = array_merge($a, $b, $c);

print_r($array);

Let's show a more complex example:

<?php
$a = [1, 2, 3];
$b = ['Simpson' => 'Homer', 'Flinstone' => 'Fred'];
$c = ['Simpson' => 'Lisa', 1, 2];
$array = array_merge($a, $b, $c);

print_r($array);

Súvisiace manuály

      Aktivity