array_merge_recursive()

array_merge_recursive ( $array1, $array1 ....)
$array1 : Required , Input array 1 .
$array2 : Required , Input array 2 .

Resultant array as output of merging of elements

Example 1

$input1=array(1,2,3,4);
$input2=array(5,6,7);
echo print_r(array_merge_recursive($input1,$input2));
Output is here.
Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 [6] => 7 ) 1

Example 2

$input1=array("one"=>'first','Second'=>'2nd',3,4);
$input2=array("Five"=>'5th',6,7);
print_r(array_merge_recursive($input1,$input2));
Output is here.
Array ( [one] => first [Second] => 2nd [0] => 3 [1] => 4 [Five] => 5th [2] => 6 [3] => 7 )

Example 3: Merging Non-Array Values

$array1 = ['color' => 'red'];
$array2 = ['color' => 'blue'];
$result = array_merge_recursive($array1, $array2);
print_r($result);  // Output: ['color' => ['red', 'blue']]

Example 4: Merging Nested Arrays

$array1 = ['info' => ['name' => 'John', 'age' => 30]];
$array2 = ['info' => ['age' => 40, 'city' => 'New York']];
$result = array_merge_recursive($array1, $array2);
print_r($result);  // Output: ['info' => ['name' => 'John', 'age' => [30, 40], 'city' => 'New York']]

Difference between arrays considering values
Array REFERENCE
Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com











    PHP video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer