PHP中的替代語法介紹
今天看了一下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代表啥?菜鳥一個(gè),沒有見過,所以就google了一下,才明白這是php的替代語法,
冒號(:)等價(jià)于左花括號({),endif等價(jià)于右花括號(});
舉個(gè)例子吧:
<?php if ($a<0): ?>
是負(fù)數(shù)拉
<?php endif; ?>
上面的語句等同于
<?php if ($a<0){ ?>
是負(fù)數(shù)拉
<?php } ?>
PHP中那些語法有替代語法?
流程控制(包括if,while,forforeach,switch)這幾個(gè)語句有替代語法。
替代語法的基本形式:
左花括號({)換成冒號(:),把右花括號(})分別換成 endif;,endwhile;,endfor;,endforeach; 以及 endswitch;
while替代語法:
<?php while (expr): ?>
<li>循環(huán)點(diǎn)什么</li>
<?php endwhile; ?>
其它替代語法可以類推。
相關(guān)文章
做了CDN獲取用戶真實(shí)IP的函數(shù)代碼(PHP與Asp設(shè)置方式)
asp取真實(shí)IP的代碼,搭環(huán)境測試無代理、一級或多級代理的情況,可以正常獲取2013-04-04PHP跳出for循環(huán)中的break和continue
在PHP中,可以使用break關(guān)鍵字來跳出循環(huán),,PHP中還可以使用continue關(guān)鍵字跳過本次循環(huán)并繼續(xù)執(zhí)行下一次循環(huán),當(dāng)循環(huán)執(zhí)行到continue語句時(shí),本次循環(huán)中continue之后的代碼將不再執(zhí)行,直接進(jìn)入下一次循環(huán)2023-09-09如何獲知PHP程序占用多少內(nèi)存(memory_get_usage)
想要知道編寫的 PHP 腳本需要占用多少內(nèi)存么?很簡單,直接使用 PHP 查看當(dāng)前分配給 PHP 腳本的內(nèi)存的函數(shù) memory_get_usage() 就可以了2012-09-09解析php中array_merge與array+array的區(qū)別
本篇文章是對php中array_merge與array+array的區(qū)別進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06