Is it possible to remove a string (see example below) from a PHP array without knowing the index?
Example:
array = array("string1", "string2", "string3", "string4", "string5");
I need to remove string3.
|
if you think your value will be in their more than once try using array_keys with a search value to get all of the indexes. You'll probably want to make sure |
|||||
|
It sort of depends how big the array is likely to be, and there's multiple options. If it's typically quite small, array_diff is likely the fastest consistent solution, as Jorge posted. Another solution for slightly larger sets:
But that's only good if you don't have duplicate items. Depending on your workload it might be advantageous to guarantee uniqueness of items too. |
|||
|