Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created July 27, 2019 01:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/c77f094cc81772fea232979f680b24f4 to your computer and use it in GitHub Desktop.
Save parzibyte/c77f094cc81772fea232979f680b24f4 to your computer and use it in GitHub Desktop.
Manual array merge in PHP https://parzibyte.me/blog
<?php
// https://parzibyte.me/blog
$gatos = array("Michi", "Misifú");
$perros = array("Maggie", "Guayaba");
# Creamos el resultado, que al principio es el primer arreglo
$mascotas = $gatos;
// Al que vamos a adjuntar lo recorremos
foreach ($perros as $perro) {
// Y en cada paso, agregamos el valor al otro
array_push($mascotas, $perro);
}
print_r($mascotas);
/*
Array
(
[0] => Michi
[1] => Misifú
[2] => Maggie
[3] => Guayaba
)
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment