Show all what not in field array

Hi guys, I have problem with my template part. I have this solution that will show all items, that = $onlyshow. I need to rewrite this code to show all variables that != $onlyshow

<?php foreach(page('bookmaker')->children()->visible()->limit(99) as $bookmaker_item): ?>
    <ul class="list-unstyled list split-list">
    <?php foreach($bookmaker_item->excluded_countries()->split() as $bookmaker_country): ?>
    <?php $onlyshow = array($country->country_name()); ?>
    <?php if(in_array($bookmaker_country, $onlyshow)) { ?>
    <li><a href="<?php echo $bookmaker_item->url() ?>"><?php echo $bookmaker_item->title()->html() ?></a><li>
    <?php } ?>
    <?php endforeach ?>
     </ul>
    <?php endforeach ?>
<?php if(! in_array($bookmaker_country, $onlyshow)): ?>
...
<?php endif ?>

Yep, but it shows all items many times as much $bookmaker_item->title() have $bookmaker_item->excluded_countries() is it possible to show $bookmaker_item->title() only one time? http://take.ms/NCczG

Then you have to remove the inner foreach loop and just check if the elements of one array are in the other:

<?php foreach(page('bookmaker')->children()->visible()->limit(99) as $bookmaker_item): ?>
    <ul class="list-unstyled list split-list">
      <?php 
       $excludedCountries = $bookmaker_item->excluded_countries()->split();
       $onlyshow = array($country->country_name());
       if(empty(array_intersect($excludedCountries, $onlyshow))): ?>
         <li><a href="<?php echo $bookmaker_item->url() ?>"><?php echo $bookmaker_item->title()->html() ?></a><li>
       <?php endif ?>
    </ul>
<?php endforeach ?>
1 Like

Yep all is correct! just need fix add “)”
if(empty(array_intersect($excludedCountries, $onlyshow)): ?>

I always seem to forget some parenthesis when editing code here … corrected it above.

1 Like