如何优化php语法
下面的PHP调用工作正常,但可能有另一种更干净的方式来显示相同的内容如何优化php语法,php,if-statement,Php,If Statement,下面的PHP调用工作正常,但可能有另一种更干净的方式来显示相同的内容 <?php if ($this['modules']->count('top-a')) : ?> <?php if ($this['config']->get('warp_onlyhome')) : ?> <?php $catid = JRequest::getInt('catid'); if ($catid == 0) : ?> <
<?php if ($this['modules']->count('top-a')) : ?>
<?php if ($this['config']->get('warp_onlyhome')) : ?>
<?php $catid = JRequest::getInt('catid'); if ($catid == 0) : ?>
<section id="top-a" class="grid-block"><?php echo $this['modules']->render('top-a', array('layout'=>$this['config']->get('top-a'))); ?></section>
<?php endif ?>
<?php else: ?>
<section id="top-a" class="grid-block"><?php echo $this['modules']->render('top-a', array('layout'=>$this['config']->get('top-a'))); ?></section>
<?php endif; ?>
<?php endif; ?>
这是如何使用if-else嵌入的示例
<? if ($condition): ?>
<p>Content</p>
<? elseif ($other_condition): ?>
<p>Other Content</p>
<? else: ?>
<p>Default Content</p>
<? endif; ?>
内容
其他内容
默认内容
请参阅和。您使用的
其他:
<?php if ($this['config']->get('warp_onlyhome')) : ?>
<?php $catid = JRequest::getInt('catid'); if ($catid == 0) : ?>
my content goes here
<?php endif: ?>
<?php else: ?>
my content 2
<?php endif; ?>
在你提出这样的问题之前,先阅读一本书或一篇教程……谢谢!你的答案正是我需要的!
if ($this['config']->get('warp_onlyhome')) {
$catid = JRequest::getInt('catid');
if ($catid == 0) {
echo "my content goes here";
}
} else {
echo "my content 2";
}