Answers for "array push syntax php"

PHP
68

php append to array

$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]
Posted by: Guest on January-21-2020
5

php add item to array

<?php
  $z = ['me','you', 'he'];
  array_push($z, 'she', 'it');
  print_r($z);
?>
Posted by: Guest on June-02-2020
1

php array append

<?php
$stack = array("orange", "banana");
array_push($stack, "apple", "raspberry");
print_r($stack);
?>
Posted by: Guest on October-01-2020

Browse Popular Code Answers by Language