php append to array
snippet in php

php append to array

user4439

$myArr = [1, 2, 3, 4];

array_push($myArr, 5, 8);
print_r($myArr); // [1, 2, 3, 4, 5, 8]

$myArr[] = -1;
print_r($myArr); // [1, 2, 3, 4, 5, 8, -1]

php array add

user3259

<?php
$a=array("red","green");
array_push($a,"blue","yellow");
print_r($a);
?>

php add item to array

user8928

<?php
  $z = ['me','you', 'he'];
  array_push($z, 'she', 'it');
  print_r($z);
?>

php append element to array

user1905

array_push($cart, 13);

add item to array in php

user2776

<?php

$a=array("red","green");

array_push($a,"blue","yellow");

print_r($a);
?>

add array to array php

user8271

<?php
$array1 = array("color" => "red", 2, 4);
$array2 = array("a", "b", "color" => "green", "shape" => "trapezoid", 4);
$result = array_merge($array1, $array2);
/*
Array
(
    [color] => green
    [0] => 2
    [1] => 4
    [2] => a
    [3] => b
    [shape] => trapezoid
    [4] => 4
)
*/
?>