magnusalex Posted March 17, 2011 Share Posted March 17, 2011 Hi, I have an array filled with values like this: string(1) "Acer 1" string(2) "Acer 2" string(3) "Dell 1" string(4) "Dell 2" string(5) "Dell 3" string(6) "Dell 4" string(7) "Acer 3" string( "Acer 4" Is there a way to successfully remove all array strings that starts with a given value like "Acer"? I tried with this snippet, does not work: foreach($array as &$value) { if(preg_match("/^Acer/", $value)) { unset($value); } } Any ideas will be appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/230910-is-there-a-way-to-remove-array-values-based-on-its-value/ Share on other sites More sharing options...
bh Posted March 17, 2011 Share Posted March 17, 2011 Hi, foreach($array as $key => $value) { if(preg_match("/^Acer/", $value)) { unset($array[$key]); } } Quote Link to comment https://forums.phpfreaks.com/topic/230910-is-there-a-way-to-remove-array-values-based-on-its-value/#findComment-1188622 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.