How can values in an array be replaced in PHP?

To replace values in an array in PHP, you can use the array_replace() function. This function takes multiple arrays as arguments and replaces the values of the first array with the values from the subsequent arrays. This allows you to update specific values in an array without modifying the original array.

// Original array
$originalArray = array('a' => 1, 'b' => 2, 'c' => 3);

// Array with values to replace
$valuesToReplace = array('b' => 5, 'c' => 7);

// Replace values in the original array
$updatedArray = array_replace($originalArray, $valuesToReplace);

// Print the updated array
print_r($updatedArray);