php add element to array
snippet in php

php append to array

user7861

$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]

array push php

user3901


<?php

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

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

print_r($a);
?>
 

php array add

user8745

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

array_push php

user1631


<?php
$cesta = array("laranja", "morango");
array_push($cesta, "melancia", "batata");
print_r($cesta);
?>

php add item to array

user847

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

php add element to array

user2592


<?php
$stack = array("orange", "banana");
array_push($stack, "apple", "raspberry");
?>