PHP Array Function : array_replace()

The array_replace() function is used to replace the values of the first array with the values from the next/second array. The syntax is as follows :
 array_replace(array1, array2);
Where array1 and array2 are names of arrays. The function returns the replaced array, or NULL if an error occurs.

Example :

  $my_arr1 = array("HTML", "CSS", "JavaScript");
  $my_arr2 = array("Java", "C++", "Objective C");

  $new_arr = array_replace($my_arr1, $my_arr2);

  $len = count($new_arr);
  for($x = 0; $x < $len; $x++) {
    echo $new_arr[$x] . ", ";

Output :

Java, C++, Objective C,

Next Topic :