vijdev Posted September 7, 2010 Share Posted September 7, 2010 are all of the following same, or some same or all different: $variable="" $variable=0 $variable=NULL and which of the above will satisfy if(empty($variable)) { blah!; } Link to comment https://forums.phpfreaks.com/topic/212768-question-about-similar-variable-values/ Share on other sites More sharing options...
PFMaBiSmAd Posted September 7, 2010 Share Posted September 7, 2010 There's a table in the documentation that shows what is considered to be 'empty' - http://php.net/manual/en/types.comparisons.php You could also just test each of those values using some code to see for yourself. Link to comment https://forums.phpfreaks.com/topic/212768-question-about-similar-variable-values/#findComment-1108270 Share on other sites More sharing options...
rwwd Posted September 7, 2010 Share Posted September 7, 2010 Hi there Vijdev, $variable=""; //Setting var as empty or setting it for later, quotes mean string $variable=0//numerical value or can be boolean $variable=NULL//Same as the top one, but useful for passing into functions as an optional paramter and and which of the above will satisfy if(empty($variable)) { echo "blah!"; } The top one, and if nothing is sent into the last one, that can be construed as empty/not set. Bearing in mind that isset() and empty() have similar uses - BUT empty checks to see if there is any value in the variable, this is useful to check session/cookie data etc. Hope that helps a little. Cheers, Rw Link to comment https://forums.phpfreaks.com/topic/212768-question-about-similar-variable-values/#findComment-1108272 Share on other sites More sharing options...
vijdev Posted September 7, 2010 Author Share Posted September 7, 2010 thanks rwwd and PFMaBiSmAd. both your answers were great to help me! Link to comment https://forums.phpfreaks.com/topic/212768-question-about-similar-variable-values/#findComment-1108276 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.