标签:缩写

PHP代码缩写

2009-08-05 16:00:001984 点击

适才在 Jblog 的代码中看到一段PHP代码缩写,备忘一下,积累知识。

  1. !defined('IN_JBLOG') && exit('Access Denied!'); 

从直觉上看,这段代码也没有什么出众之处,也就是一个 if 判断,Google 了一下,网上没有太多关于PHP代码缩写规则的文章,在php吧看到关于PHP代码 if 的缩写,可以使用三元表达式来处理。

  1. if($foo) {  
  2.     $str = 'yes';  
  3. else {  
  4.     $str = 'no';  

可以缩写成:

  1. ($foo) ? ($str = 'yes') : ($str = 'no'); 

阅读全文…

学习笔记 PHP代码缩写