Find the differences between array_replace() and array_replace_recursive() in PHP

Description

The following code shows how to find the differences between array_replace() and array_replace_recursive().

Example


/*from   ww w .j a v  a 2 s  .com*/
<?php
    $a1=array("a"=>array("red"),"b"=>array("green","blue"),);
    $a2=array("a"=>array("yellow"),"b"=>array("black"));

    $result=array_replace_recursive($a1,$a2);
    print_r($result);

    $result=array_replace($a1,$a2);
    print_r($result);
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Data Types »




Array
Array Associative
Array Util
ArrayObject
Data Types
Date
Date Format
DateTime
Number
String
String Escape
String Filter
String HTML
String Type
Timezone