Function to replace array elements – PHP

<?php
 $testArray = array("orange", "banana", "apple", "raspberry");
 $replaceArr1 = array(0 => "pineapple", 3 => "cherry");
 $replaceArr2 = array(0 => "grape");
 $basket = array_replace($testArray, $replaceArr1, $replaceArr2);
 print_r($basket);
 //Array ( [0] => grape [1] => banana [2] => apple [3] => cherry )
?>

Leave a Reply

Your email address will not be published. Required fields are marked *