Replace values in first associative array ($a1) with values in second array ($a2) with numeric keys in PHP

Description

The following code shows how to replace values in first associative array ($a1) with values in second array ($a2) with numeric keys.

Example


//  ww w.  j a  va 2 s  . c  o m

<?php
    $a1=array("red","green","blue","yellow");
    $a2=array(0=>"orange",3=>"Pink");
    print_r(array_replace($a1,$a2));
?>

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