知识点
相关文章
更多最近更新
更多PHP中的替代语法
2019-03-02 01:03|来源: 网路
今天看了一下wordpress的代码,里面有些少见的php替代语法,
<?php else : ?> <div class="entry-content"> <?php the_content( __( 'Continue reading <span class="meta-nav">→</span>', 'thebox' ) ); ?> <?php wp_link_pages( array( 'before' => '<div class="page-links">' . __( 'Pages:', 'thebox' ), 'after' => '</div>' ) ); ?> </div><!-- .entry-content --> <?php endif; ?>
else后面的冒号和endif代表啥?菜鸟一个,没有见过,所以就google了一下,才明白这是php的替代语法,
冒号(:)等价于左花括号({),endif等价于右花括号(});
举个例子吧:
<?php if ($a<0): ?>
是负数拉
<?php endif; ?>
上面的语句等同于
<?php if ($a<0){ ?>
是负数拉
<?php } ?>
PHP中那些语法有替代语法?
流程控制(包括if,while,forforeach,switch)这几个语句有替代语法。
替代语法的基本形式:
左花括号({)换成冒号(:),把右花括号(})分别换成 endif;,endwhile;,endfor;,endforeach; 以及 endswitch;
while替代语法:
<?php while (expr): ?>
<li>循环点什么</li>
<?php endwhile; ?>
其它替代语法可以类推。
搜索微信号:ruixin,或者扫描下方二维码,关注博客公众号,不定期补脑互联网:
转自:http://www.cnblogs.com/ido321/p/3927890
相关问答
更多-
虽然这将是一个更简洁的语法,但不幸的是,这是不可能的。 你能做的最好的是: $store[new KeyObject()] = new ValueObject(); 要么 $store->append( new KeyObject(), new ValueObject()); 将对象添加到SplObjectStorage 。 While it would be a more concise syntax, unfortunately it's not possible. The best you can ...
-
唯一的问题 $query ="SELECT * from `jos_menu` where `id` = ".'\".$parent.'\"; 那是你错过了几个' : $query ="SELECT * from `jos_menu` where `id` = ".'\"'.$parent.'\"'; 在PHP中,字符串可以是: $var = 'This is a string'; 要么 $var = "This is a string"; 如果你想把"你已经开始的字符串放在里面" ,你需要告诉PHP, ...
-
函数中的PHP语法(PHP Syntax in functions)[2023-05-14]
您的$ rows变量不存在于deleteButton函数的范围内。 你可以像这样修改它: function deleteButton($rows) { // etc } 然后将其称为: deleteButton($rows); Your $rows variable doesn't exist in the scope of the deleteButton function. You could amend it like this: function deleteButton($rows) ... -
尝试这个: the [url=http://feeds.feedburner.com]hello[/url].
Also [url=http://feeds.feedburner.com][/url].
'; echo highlight_string($str); ?> 输 ... -
PHP中的语法和变量(Syntax and Variables in PHP)[2023-07-03]
您可以直接将变量写入双引号字符串,请参阅http://www.php.net/manual/en/language.types.string.php#language.types.string.parsing echo "'location_$z' => \$location_$z,"; 您可能还需要阅读字符串文档的其余部分 You can just write variables directly into double quoted strings see http://www.php.net/man ... -
这将被称为Heredoc That would be called a Heredoc
-
它本身没有任何其他PHP代码在页面上,它是无用的,几乎肯定会导致错误。 但是,在大多数情况下,页面上的某个位置有一个函数或控件结构,这只是一个结束括号。 例如
Some title only shown if PHP condition is met.
All by itself without any other PHP code on the page, it is useles ... -
PHP中的大括号语法?(Curly brace syntax in PHP?)[2022-03-11]
在goto文档中, target:语法不被称为任何东西,它只是表示goto能够跳转到的目标。 花括号不代表任何事物,除了属于该目标的代码之外。 正如在这个评论中 ,大括号只是使目标语法更清晰。 目标只与goto有关。 目标不是(也不是)变量,也不是一个对象。 这个. PHP中的语法是一个字符串连接操作符,因为testing和process目标不是字符串,它会抛出一个错误,指出. 出乎意料。 既然他们不是对象,你也不能去goto testing->process; 由于testing不是自己的process ... -
PHP语法中的JavaScript(JavaScript in PHP Syntax)[2023-08-28]
你正在合并php和javascript。 将它们分开。 url: ""+caNumber; You are merging both php and javascript. Keep them separate. url: "php代码中的语法错误(Syntax error in php code)[2022-11-17]
应该在两个字符串之间使用concatenation operator ('.') 试试这个 $query = ("UPDATE cegek SET CegNev='".$cegnev."', Kozpont='".$kozpont."', Bevetel='".$bevetel."', Alkalmazottak='".$alkalmazott."', Iparag='".$iparag."' WHERE id=".$id.""); Should use concatenation operator (' ...