In order to remove an element from an array, we can use unset() function which removes the element from an array and then use array_search() function which indexes the array numerically automatically. Function Used: unset(): This function unsets a given variable.
1 2 3 | if (($key = array_search('strawberry', $array)) !== false) { unset($array[$key]); } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.