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.
$index = array_search('string3',$array); if($index !== FALSE){ unset($array[$index]); }
if you think your value will be in there more than once try using array_keys with a search value to get all of the indexes. You'll probably want to make sure
EDIT:
Note, that indexes remain unchanged when using unset
. If this is an issue, there is a nice answer here that shows how to do this using array_splice
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With