How can I use the array_splice function to remove and replace elements in an array in PHP? Example code: - Biz Tech

How can I use the array_splice function to remove and replace elements in an array in PHP? Example code:

Listen
$fruits = array("apple", "banana", "orange", "grape", "peach");

// Remove two elements starting from index 2
array_splice($fruits, 2, 2);

print_r($fruits);

// Replace two elements starting from index 1 with "cherry"
array_splice($fruits, 1, 2, "cherry");

print_r($fruits);