0

So I currently have this, so if $iDontWant matches something in the array from $data->Name, it removes the whole line. Using the same method how could I do the same but with multiple $iDontWant? So say another $iDontWant2, and this also remove from the foreach? Every way I have tried seems to break things!

$iDontWant="bla"

foreach($datas as $data) {
    if($data->Name == $iDontWant) continue; 
    echo '<div class="checkmark-33"><div class="fa-stack fa-1x checkmark-icon"><i class="fa fa-circle fa-stack-2x icon-background"></i><i class="fa fa-check fa-stack-1x icon-text"></i></div><div class="checkmark-inner">'. $data->Name .'</div></div>'; 
}; ?>

Any help would be great, thanks!

2 Answers 2

5

Declare $iDontWant as an array and use in_array():

$iDontWant = ["one", "two"];

foreach($datas as $data) {
    if(in_array($data->Name, $iDontWant)) {
        continue;
    }
}
Sign up to request clarification or add additional context in comments.

Comments

0

As an alternative to only loop the ones you want, just take the difference and loop that:

$iDontWant = ["one", "two"];

foreach(array_diff($datas, $iDontWant) as $data) {
    echo '<div class="checkmark-33"><div class="fa-stack fa-1x checkmark-icon"><i class="fa fa-circle fa-stack-2x icon-background"></i><i class="fa fa-check fa-stack-1x icon-text"></i></div><div class="checkmark-inner">'. $data->Name .'</div></div>'; 
}

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.