0

this is my array output

Array ( [0] => Site=[121] [1] => #asasasas [2] => Devices=34343 [3] => DeviceID=[hjhghg])

Now I want to remove the value with key if it value contains # symbol... I have tried this, but does not seem to work....

foreach ($myarray as $key=>$value) {
    if (strpos($value,'#') !== false) {
        unset(($myarray[$key]);
    }
}

any ways to fix this??

Updated this is my actual array array_values($lines) i have already tried this...

if(strpos($value,'#') !== false) {
                           unset(array_values($lines)[$key]);
                       }
1
  • 1
    try removing extra ( in unset Commented Aug 7, 2014 at 4:02

2 Answers 2

1

You have one too many opening parentheses after unset

Sign up to request clarification or add additional context in comments.

Comments

0

This works fine for me

$arr = array (  0 => 'Site=[121]',
        1 => '#asasasas',
        2 => 'Devices=34343', 
        3 => 'DeviceID=[hjhghg]'
      );
foreach($arr as $key => $val){
  if(strpos($val,'#') !== false) {
       unset($arr[$key]);
   }
}
print_r($arr);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.