PHP array_merge_recursive() – Recursively Merges One or More Arrays
The article explains how PHP's array_merge_recursive() function combines multiple arrays by recursively merging values with identical keys, describes its parameters and return value, and provides a complete code example with expected output.
The PHP function array_merge_recursive() merges one or more arrays recursively, appending values from later arrays to earlier ones and combining values with identical string keys into sub‑arrays.
Parameters array1 – the initial array to merge. ... – additional arrays to be merged recursively.
Return value
An array containing the merged values.
Example
<?php
$ar1 = array("color" => array("favorite" => "red"), 5);
$ar2 = array(10, "color" => array("favorite" => "green", "blue"));
$result = array_merge_recursive($ar1, $ar2);
print_r($result);
?>The output shows that the color key now holds an array with both favorite values (“red” and “green”) and the additional blue entry, while numeric values are appended.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Laravel Tech Community
Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
