Answers for "add variables to php array"

PHP
6

add item to array in php

<?php

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

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

print_r($a);
?>
Posted by: Guest on May-25-2020
1

php add array to array

$a = array('a','b','c');
$b = array('c','d','e');

array_push($a, ...$b);
print_r($a);
/*
notice this is different than array merge as it does not merge
values that the same 
Array
(
    [0] => a
    [1] => b
    [2] => c
    [3] => c
    [4] => d
    [5] => e
)
*/
Posted by: Guest on February-22-2022

Browse Popular Code Answers by Language