Maison  >  Article  >  développement back-end  >  如何循环带条件的数组

如何循环带条件的数组

WBOY
WBOYoriginal
2016-06-23 13:47:23758parcourir

下面这个数组

$abc=array(     [navigation_list] => Array        (            [0] => Array                (                    [navigation_id] => 1                    [navigation_title] => 题目1                    [navigation_link] => http://127.0.0.1/                    [navigation_sort] => 255                    [navigation_open_type] => 1                )            [1] => Array                (                    [navigation_id] => 2                    [navigation_title] => 题目2                    [navigation_link] => http://127.0.0.1/circle                    [navigation_sort] => 255                    [navigation_open_type] => 1                )            [2] => Array                (                    [navigation_id] => 3                    [navigation_title] => 题目3                    [navigation_link] => http://127.0.0.1/microshop                    [navigation_sort] => 255                    [navigation_open_type] => 1                )            [3] => Array                (                    [navigation_id] => 4                    [navigation_title] => 题目4                    [navigation_link] => http://127.0.0.1/shop/index.php?act=brand                    [navigation_sort] => 255                    [navigation_open_type] => 1                )        ))

如果我想循环出后面二个数组,即前面两个不要,怎么写条件呢
下面代码是我写的,为啥循环不出来呢,哪里错了:
<?php             if ($abct[navigation_list][navigation_id]>2 || $output[navigation_list][navigation_id]>5){      foreach($output['navigation_list'] as $value) {?>      <li class="link"><a href="<?php echo $value['navigation_link'];?>" <?php echo $value['navigation_open_type']=='1'?'target="_blank"':'';?>><?php echo $value['navigation_title'] ?></a></li>      <?php } ?>      <?php }?>


回复讨论(解决方案)

<?php      foreach($abc['navigation_list'] as $value) {?><?php if ($value['navigation_id']>2){ ?>           <li class="link"><a href="<?php echo $value['navigation_link'];?>" <?php echo $value['navigation_open_type']=='1'?'target="_blank"':'';?>><?php echo $value['navigation_title'] ?></a></li>      <?php } ?>      <?php }?>

Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Article précédent:PHP+mysql的一个问题Article suivant:php json数组问题