标签:
$a =1; $b = 0; if (isset( $a )){ $b =1; print ( $b . "\n" ); } if ( $b !=0){ print ( $b . "\n" ); } |
简化后:
$a =1; $b = 0; isset( $a ) && ( $b =1) && print ( $b . "\n" ); $b == 0 || print ( $b . "\n" ); |
明显代码看起来更加整齐,更加简单!
$a = 1; if ( $a = 1){ echo ‘$a == 1‘ ; } |
之后:
$a = 1; if (1 = $a ){ echo ‘$a == 1‘ ; } |
明显,常量放在前面的话,编译器就能判断错误。
正规格式:
$a = 1; if (1 == $a ){ echo ‘$a == 1‘ ; } |
/*错误码:4,5,7,8的时候返回状态1,错误码是1,3,6返回状态2*/ $error = 4; $state = 0; if ( $error == 4 || $error == 5 || $error == 7 || $error == 8){ $state = 1; } if ( $error == 1 || $error == 3 || $error == 6){ $state = 2; } echo "$state \n" ; |
/*错误码:4,5,7,8的时候返回状态1,错误码是1,3,6返回状态2*/ $error = 4; $state = 0; $arr = array (4 => 1, 5 => 1, 7 => 1, 8 => 1, 1 => 2, 3 => 2, 6 => 2); isset( $arr [ $error ]) && ( $state = $arr [ $error ]); echo "$state \n" ; |
明显代码更加凝练,更加清楚,更易懂,速度也更快!
标签:
原文地址:http://www.cnblogs.com/shouce/p/5260473.html