php foreach如何分组?我已经尝试了5天,但仍然无法使用我不知道php foreach它是如何工作的,但我正在学习它,谢谢大家的建议
原始的PHP:
<?php if(isset($this->leading) && count($this->leading)): ?>
<?php foreach($this->leading as $key=>$item): ?>
<?php
$this->item=$item;
echo $this->loadTemplate('item');
?>
<?php endforeach; ?>
<?php endif; ?>
<?php if(isset($this->primary) && count($this->primary)): ?>
<?php foreach($this->primary as $key=>$item): ?>
<?php
$this->item=$item;
echo $this->loadTemplate('item');
?>
<?php endforeach; ?>
<?php endif; ?>
<?php if(isset($this->secondary) && count($this->secondary)): ?>
<?php foreach($this->secondary as $key=>$item): ?>
<?php
$this->item=$item;
echo $this->loadTemplate('item');
?>
<?php endforeach; ?>
<?php endif; ?>
我试过了
<?php if(isset($this->leading) && count($this->leading)) && (isset($this->primary) && count($this->primary)) && (isset($this->secondary) && count($this->secondary)): ?>
<!-- Leading items -->
<?php foreach (array($this->leading, $this->primary, $this->secondary) as $key=>$item) ($this->leading as $key=>$item): ?>
<?php
// Load category_item.php by default
$this->item=$item;
echo $this->loadTemplate('item');
?>
<?php endforeach; ?>
<?php endif; ?>
但不工作
一如既往,感谢您的帮助!
感谢大家:)
谢谢,史蒂文!