Last active
February 25, 2016 10:08
-
-
Save davidyell/6630267 to your computer and use it in GitHub Desktop.
The outcomes of testing things using just if() is.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* As I never am quite sure the outcome of testing variables and arrays using | |
* just the plain if(), I thought I'd make a quick test so that I can refer to | |
* it when I next forget this! | |
* | |
* Manual ref: http://uk3.php.net/manual/en/language.types.boolean.php#language.types.boolean.casting | |
*/ | |
$emptyArray = array(); // False | |
$filledArray = array('One','Two'); // True | |
$boolTrue = true; // True | |
$boolFalse = false; // False | |
$boolNull = null; // False | |
$emptyString = ''; // False | |
$filledString = 'A string'; // True | |
if ($emptyArray) { | |
var_dump('If thinks emptyArray is true'); | |
} | |
if ($filledArray) { | |
var_dump('If thinks filledArray is true'); | |
} | |
if ($boolTrue) { | |
var_dump('If thinks boolTrue is true'); | |
} | |
if ($boolFalse) { | |
var_dump('If thinks boolFalse is true'); | |
} | |
if ($boolNull) { | |
var_dump('If thinks boolNull is true'); | |
} | |
if ($emptyString) { | |
var_dump('If thinks emptyString is true'); | |
} | |
if ($filledString) { | |
var_dump('If thinks filledString is true'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment