robert_gsfame Posted September 18, 2009 Share Posted September 18, 2009 I just want to get more explanation regarding strcmp What i know is that using strcmp will return value 0,1, or 2 So what does this syntax actually mean if(!(Strcmp(case1,case2)){ echo "blabla" can anyone tell me ? Quote Link to comment Share on other sites More sharing options...
Bricktop Posted September 18, 2009 Share Posted September 18, 2009 Hi robert_gsfame, strcmp compares two strings, and returns less than (<0), greater than (>0) or identical (0). So: <?php echo strcmp("Hello world","Hello world"); ?> Would return: 0. <?php echo strcmp("1","2"); ?> Would return: <0. <?php $string1 = "abc"; $string2 = "def"; $string3 = "XYZ"; if (strcmp($sstring1, $sstring2) < 0) { print "$sstring1 is smaller than $string2<br>"; } else { print "$string2 is smaller than $string1<br>"; } if (strcmp($string1, $string3) < 0) { print "$string1 is smaller than $string3<br>"; } else { print "$string3 is smaller than $string1<br>"; } ?> Would return: abc is smaller than def XYZ is smaller than abc Your code example is using the incorrect syntax, so would not work. The PHP manual on strcmp (http://us.php.net/manual/en/function.strcmp.php) also has some good code snippets at the bottom of the page which should help explain this function further. I hope this helps. Quote Link to comment Share on other sites More sharing options...
robert_gsfame Posted September 18, 2009 Author Share Posted September 18, 2009 if (strcmp($sstring1, $sstring2) what is the default value for this?? less than 0,0 or greater than 0 anyway i use if(!(strcmp(case1,case2)){ echo "SELECTED" in order to retrieve the value from the database into my list menu and for sure it works Can you explain this to me Quote Link to comment Share on other sites More sharing options...
Bricktop Posted September 18, 2009 Share Posted September 18, 2009 Hi robert_gsfame, Sorry, I misread the location of the ! in your original post! Anyway, the default value for: if (strcmp($sstring1, $sstring2) all depends on what $sstring1 and $sstring2 are. There is no "default" value as such, strcmp takes two strings and compares them. It all depends on what the strings contain as to what value will be returned. Hope this helps. Quote Link to comment 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.