/***************************by garcon1986********************************/ <?php //php avancé 5 example $a = 'hello'; $a .= 'world'; $table = 'users'; $id = 5; $sql = 'SELECT * FROM'.$table. "WHERE ID = '$id'"; //date() G显示24小时的格式,i显示分钟 echo 'il est'.date('G /h i').'il fait beau<p>'; // '=', '==', '===' 三者区别: '='是赋值,右边的值赋给左边;'=='是值相等,类型不一定等;'==='是恒等,值相等类型也相等;'!=='是值不等,或类型不等。 $a = '34'; $b = 34; $a == $b; //echo (boolean)($a == $b); var_dump((bool) $a == $b); echo '<br>'; $a === $b; //echo (boolean)($a === $b); var_dump((bool) $a === $b); echo '<br>'; var_dump((bool)($a !== $b)); echo '<p>'; //arithmetic operator echo 5*"", '<br>'; //0 echo 5+false, '<br>'; //5 echo 5/NULL, '<br>'; //Warning: Division by zero //assignment operator $a = ($b = 4) + 5; // $a 现在成了 9,而 $b 成了 4。 echo "$a,$b<br>"; $a = 3; $a += 5; // sets $a to 8, as if we had said: $a = $a + 5; $b = "Hello "; $b .= "There!"; // sets $b to "Hello There!", just like $b = $b . "There!"; echo "$a,$b<br>"; //bitwise operator echo 12 ^ 9; // 输出为 '5' echo '<br>'; echo "12" ^ "9"; // 输出退格字符(ascii 8) // ('1' (ascii 49)) ^ ('9' (ascii 57)) = #8 echo '<br>'; echo "hallo" ^ "hello"; // 输出 ascii 值 #0 #4 #0 #0 #0 echo '<p>'; // 'a' ^ 'e' = #4 /* --------- --------- -- --------- result value op test --------- --------- -- --------- Bitwise AND ( 0 = 0000) = ( 0 = 0000) & ( 5 = 0101) ( 1 = 0001) = ( 1 = 0001) & ( 5 = 0101) ( 0 = 0000) = ( 2 = 0010) & ( 5 = 0101) ( 4 = 0100) = ( 4 = 0100) & ( 5 = 0101) ( 0 = 0000) = ( 8 = 1000) & ( 5 = 0101) Bitwise Inclusive OR ( 5 = 0101) = ( 0 = 0000) | ( 5 = 0101) ( 5 = 0101) = ( 1 = 0001) | ( 5 = 0101) ( 7 = 0111) = ( 2 = 0010) | ( 5 = 0101) ( 5 = 0101) = ( 4 = 0100) | ( 5 = 0101) (13 = 1101) = ( 8 = 1000) | ( 5 = 0101) Bitwise Exclusive OR (XOR) ( 5 = 0101) = ( 0 = 0000) ^ ( 5 = 0101) ( 4 = 0100) = ( 1 = 0001) ^ ( 5 = 0101) ( 7 = 0111) = ( 2 = 0010) ^ ( 5 = 0101) ( 1 = 0001) = ( 4 = 0100) ^ ( 5 = 0101) (13 = 1101) = ( 8 = 1000) ^ ( 5 = 0101) */ //comparison operator var_dump(0 == "a"); // 0 == 0 -> true echo '<br>'; var_dump("1" == "01"); // 1 == 1 -> true echo '<br>'; var_dump("1" == "1e0"); // 1 == 1 -> true echo '<br>'; switch ("a") { case 0: echo "0"; break; case "a": // never reached because "a" is already matched with 0 echo "a"; break; } echo '<p>'; //error control operator //execution operator $output =`ls -al`; echo "<pre>$output</pre>"; //increment-decrement operator $i = 'W'; for ($n=0; $n<6; $n++) { echo ++$i . "/n"; } echo "<h3>Postincrement</h3>"; $a = 5; echo "Should be 5: " . $a++ . "<br />/n"; echo "Should be 6: " . $a . "<br />/n"; echo "<h3>Preincrement</h3>"; $a = 5; echo "Should be 6: " . ++$a . "<br />/n"; echo "Should be 6: " . $a . "<br />/n"; echo "<h3>Postdecrement</h3>"; $a = 5; echo "Should be 5: " . $a-- . "<br />/n"; echo "Should be 4: " . $a . "<br />/n"; echo "<h3>Predecrement</h3>"; $a = 5; echo "Should be 4: " . --$a . "<br />/n"; echo "Should be 4: " . $a . "<br />/n"; //array operators //type operators class MyClass { } class NotMyClass { } $a = new MyClass; var_dump($a instanceof MyClass); var_dump($a instanceof NotMyClass); ?>