php add array to array – Append One Array To Another In PHP

php add array to array : Question – How to add elements to an array in PHP? – The array_merge() function merges one or more arrays into one array.

php add array to array

php append element to array – Appending arrays in PHP can be done with the array_merge() function. array_push() is a PHP function that is used to add one or more elements onto the end of an array.

The array_push function is directly responsible for this terminology.

PHP append one array to another

php append to array

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

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

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

php append element to array

array_push($member, 13);

array_push php


Don’t Miss : Array push key value pair php

php add element to array


PHP array push

Example


 'Rex' => 'sachin'
];
array_push($member, 'gambhir', 'rohit');
print_r($member);
?>

Append One Array To Another In PHP

Here is an example using just two arrays.
Example

$array1 = array('product1', 'product2');
$array2 = array('product3', 'product4');
$results = array_merge($array1, $array2);
print_r($results);

Results

Array
(
[0] => product1
[1] => product2
[2] => product3
[3] => product4
)

I hope you get an idea about php add array to array.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment