Booleans.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>use of booleans in php</title> </head> <body> <h2 style="color:pink;">use of booleans in php</h2> <div style="color:#aaa; text-align:left; padding-top:10px;"> <?php /* |------------------------------------------------------------ | Booleans are the easiest data type was introduced in PHP 4. | It can be either TRUE or FALSE and case-insensitive. |------------------------------------------------------------ */ $bool = true; if($bool) echo 'i find a true boolean'; echo "<br>"; /* |------------------------------------------------------------------ | control structure automatically converts it's argument to boolean | despite that if you want to convert a value to boolean use | bool or boolean cast. |------------------------------------------------------------------ */ $someVar = (bool)100; echo $someVar; echo "<br>"; /* |------------------------------------------------------------------ | Following values are considered FALSE while conversion | 1. boolean FALSE | 2. integer 0 (zero) | 3. float 0.0 (zero) | 4. the empty string, and the string "0" | 5. an array with zero elements | 6. an object with zero member variables | 7. NULL (including unset variables) | 8. SimpleXML objects created from empty tags |------------------------------------------------------------------ */ echo "<pre>"; var_dump((bool) true); // true var_dump((bool) false); // false var_dump((bool) 1); // true var_dump((bool) -2); // true var_dump((bool) 0); // false var_dump((bool) 2.3e5); // true var_dump((bool) 0.0); // false var_dump((bool) ""); // false var_dump((bool) "modon"); // true var_dump((bool) "false"); // true(false is a string and lenght > 0) var_dump((bool) array(22)); // true var_dump((bool) array()); // false echo "</pre>"; ?> </div> </body> </html>
No comments:
Post a Comment
leave your comments here..