robert_gsfame Posted April 16, 2010 Share Posted April 16, 2010 which one is correct if(blablabla !=="") or (blablabla !="") both in php and javascript thx Quote Link to comment https://forums.phpfreaks.com/topic/198747-really-really-basic-question/ Share on other sites More sharing options...
TeddyKiller Posted April 16, 2010 Share Posted April 16, 2010 Depends what you are wanting to do. = means IS == means EQUAL TO === means IDENTICAL TO So.. if you are checking if something is NOT EQUAL TO something. You'd use != If you are checking if something is NOT IDENTICAL TO something. You'd use !== Quote Link to comment https://forums.phpfreaks.com/topic/198747-really-really-basic-question/#findComment-1043032 Share on other sites More sharing options...
robert_gsfame Posted April 16, 2010 Author Share Posted April 16, 2010 what do u mean identical and equal, i really confused this is not about mysql but javascript function and php could u please explain a bit.....equal means everything that cope with number and identical for character?? Quote Link to comment https://forums.phpfreaks.com/topic/198747-really-really-basic-question/#findComment-1043035 Share on other sites More sharing options...
Ken2k7 Posted April 16, 2010 Share Posted April 16, 2010 Read all about it here - http://www.php.net/manual/en/language.operators.comparison.php Basically, 0 == false but 0 !== false because 0 and false are not the same type. 0 is an int. false is a boolean. Quote Link to comment https://forums.phpfreaks.com/topic/198747-really-really-basic-question/#findComment-1043041 Share on other sites More sharing options...
robert_gsfame Posted April 16, 2010 Author Share Posted April 16, 2010 okay so anything that deals with string, !== must be used instead of != which should be used for numeric (integer) Quote Link to comment https://forums.phpfreaks.com/topic/198747-really-really-basic-question/#findComment-1043043 Share on other sites More sharing options...
deanlearner Posted April 16, 2010 Share Posted April 16, 2010 the number 0 == false : returns true the number 0 === false : returns false because the data types are different the string '1' == true : returns true the string '1' === true : returns false because the data types are different Quote Link to comment https://forums.phpfreaks.com/topic/198747-really-really-basic-question/#findComment-1043044 Share on other sites More sharing options...
TeddyKiller Posted April 16, 2010 Share Posted April 16, 2010 what do u mean identical and equal, i really confused this is not about mysql but javascript function and php could u please explain a bit.....equal means everything that cope with number and identical for character?? Yes. What I mentioned works in PHP and most probably Javascript. = - Assignment == - Value equality != - Value inequality === - Type and value equality !== - Type and value inequality $date = '1'; //$date now contains the value of 1. if($date == '1') { //Checks if $date has the value of 1, and returns true. if($date != '2') { //Checks if $date does not have the value of two, and returns true. Can't think of examples with === and !== Though, what is explained above is all true. You'll probs be needing != in your statement Quote Link to comment https://forums.phpfreaks.com/topic/198747-really-really-basic-question/#findComment-1043048 Share on other sites More sharing options...
Ken2k7 Posted April 16, 2010 Share Posted April 16, 2010 okay so anything that deals with string, !== must be used instead of != which should be used for numeric (integer) Nope, not necessarily. I'll use a real-life example with the function strpos. strpos is a function that searches whether a substring of a string exists. If so, it returns the index at where the substring starts at. One possible return value is 0 (which means at the beginning of the string). strpos("phpfreaks", "php"); The string php is at the start of phpfreaks so strpos returns the number 0. However, if the substring is not found, strpos returns the boolean value false. strpos("phpfreaks", "o"); o is not in phpfreaks, so it returns false. Now, say you want to check if a substring is in a string. If you used == it won't work because 0 == false; however 0 !== false. if (strpos("phpfreaks", "o") === false) // o is not in phpfreaks Hope this helps. Quote Link to comment https://forums.phpfreaks.com/topic/198747-really-really-basic-question/#findComment-1043049 Share on other sites More sharing options...
Adam Posted April 16, 2010 Share Posted April 16, 2010 Basically === checks they are of the same data type too. Quote Link to comment https://forums.phpfreaks.com/topic/198747-really-really-basic-question/#findComment-1043054 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.