Answers for "php add array content to array"

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
4

php add variable to array

<?php
	$myArray = array(); // Init empty array

	$myArray[] = $value; // Add value to the array
?>
Posted by: Guest on February-03-2021

Browse Popular Code Answers by Language