How can you replace a value in an array in PHP?
To replace a value in an array in PHP, you can use the array_splice() function. This function allows you to remove a portion of the array and replace it with new elements. You need to specify the array, the index of the element you want to replace, the number of elements to remove (in this case, 1), and the new value you want to insert at that index.
// Original array
$originalArray = [1, 2, 3, 4, 5];
// Replace the value at index 2 with 10
array_splice($originalArray, 2, 1, 10);
// Output the modified array
print_r($originalArray);