PHP How To Remove A Array Element By Array Value

How can I remove an element of the array by a given value in PHP

You can use array_search to find the element by a given value and use unset to remove the element from the array.

if (($key = array_search($val, $array)) !== false) {
    unset($array[$key]);
}
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments