|
|
|
NewbieNotes is a little series of tips for people who are new to PHP to give them a few handy tips that the more experienced of us use often
I sometimes feel sorry for ASP developers, they miss one lovely thing we've had for a good while now. We can tell when false actually is false (they can't)
I distinctly remember reading an article in a 'technical' computer magazine where the author had no idea at all why we needed to know the dirrefence - I suppose his brain rotted through that conbstant exposure to VB!
The difference between something being false or true is, classically, whether it's zero or not. That's how the CPU handles it, after all.
The most well known example of the difference in PHP is the strpos() function. A searched for string can start right at the beginning. As PHP's index to a string starts at zerolooking for 'the' in 'the quick brown fox' would return a zero.
If it's important to find out whether 'the' is in the string an if statement won't cut it! Well, unless you use PHP, of course...
PHP knows the difference between the number zero and the boolean value false. Many functions return either something or false. You can tell the difference in PHP (poor ASP suckers!)
| if($var) { do something } will fail if $var is ither zero or false
if($var !== false) { do something } will let zero thru but block flase | |
Similarly
| | if($var === false) { do something } will block everything except a false value (not zero) | |
Whenever you see that a function returns false for some condition use it to your advantage - take pity on the ASP crowd... |
|
| Newbie Notes #5 - To double quote, or single quote, that is the question Categories : PHP, Beginner Guides, Variables | | | Automatic global variable definer Categories : PHP, Variables, Beginner Guides | | | Check parameters validity. Paranoia was designed to check the validity of the parameters that a php page will receive after a form submission. It can be used to check the variables sent by POST or GET Categories : Algorithms, HTML and PHP, PHP, Variables | | | email new items in db Categories : PHP, Email, Databases, MySQL, Beginner Guides | | | clearing variables in php3 Categories : Variables, Arrays, PHP | | | A very simple PHP single password cookie based login without usernames. Categories : PHP, Cookies, Security, Beginner Guides | | | PHP based Contact email form with multiple recipients, text file based, supports departments. Categories : PHP, Email, Beginner Guides, Filesystem | | | A simple function to prevent undefined $_POST/$_GET/$_SESSION variable errors Categories : PHP, Variables, Errors and Logging | | | Newbie Notes #8 - A cron trick Categories : PHP, CURL, Beginner Guides | | | This functions compares the current PHP version with a
desired version. Because of the 3 tiered version system, a
direct compare of a string to phpversion() will not be
accurate. Categories : PHP Configuration, PHP, Variables | | | Get the self URL of current page Categories : PHP, URLs, Beginner Guides | | | A beginner's session handling class Categories : PHP, PHP Classes, Sessions, Beginner Guides | | | Db_lib - practical example usage of database abstraction and form validation.
Categories : PHP, Form Processing, PHP Classes, Data Validation, Beginner Guides | | | Easy alert box pop-up function Categories : PHP, Java Script, Beginner Guides | | | How to control the number of decimal places when outputting numbers. Categories : PHP, Strings, Variables | |
|
|
|