abdfahim Posted October 2, 2010 Share Posted October 2, 2010 Hi, A quick help needed. I have the following code if($var==0){ return $var; } Here, if $var is assigned to zero or $var is not assigned, both cases returns true. I want only to return true when $var is assigned to zero, false otherwise. I dont want to use empty or isset function. Thanks, Quote Link to comment https://forums.phpfreaks.com/topic/215000-comapre-zero-with-unassigned-variable/ Share on other sites More sharing options...
DavidAM Posted October 2, 2010 Share Posted October 2, 2010 Equivalence operator (3 equals signs) means the value is the same and the data type is the same. An empty string or unassigned variable does not have the same data type as a numeric zero. if($var===0){ return $var; } Quote Link to comment https://forums.phpfreaks.com/topic/215000-comapre-zero-with-unassigned-variable/#findComment-1118383 Share on other sites More sharing options...
abdfahim Posted October 2, 2010 Author Share Posted October 2, 2010 I am not sure about that. The reason is, if I have an array consisting both numbers and texts, and then I want to compare one array element with zero using Equivalence operator, it might not match, ryt? Quote Link to comment https://forums.phpfreaks.com/topic/215000-comapre-zero-with-unassigned-variable/#findComment-1118388 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.