我有一个名为$pages的数组内容如下:
Array ( [01-about-us] => Page Object ( [_uri] => about-us [_menuItem] => 01 [_visable] => 1 ) [02-contact] => Page Object ( [_uri] => contact [_menuItem] => 02 [_visable] => 1 ) [_sitemap] => Page Object ( [_uri] => sitemap [_menuItem] => [_visable] => ) [home] => Page Object ( [_uri] => home [_menuItem] => [_visable] => 1 ) )
<?PHP foreach($pages->_visible() AS $p): ?> <li> page </li> <?PHP endforeach ?>
不,你必须使用if:
原文链接:https://www.f2er.com/php/136256.htmlforeach ($pages as $page) { if ($page->_visible == 1) { echo "<li>page</li>"; } }
(注意你在阵列中可见拼错,也许是拼写错误?)