PHP Remove Value from Array with array_diff()

You can use the array_diff() function to remove specific values from an array. Here is an example:

$myArray = array("apple", "banana", "cherry", "apple");

$newValue = "apple";

$newArray = array_diff($myArray, array($newValue));

print_r($newArray);

In the example above, we first created an array $myArray that contains multiple duplicate values. Then, we used the array_diff() function to remove the specific value “apple” from the array. Lastly, we used the print_r() function to display the values of the new array $newArray.

bannerAds