Why do we even use strcmp???

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tores
Forum Contributor
Posts: 120
Joined: Fri Jun 18, 2004 3:04 am

Why do we even use strcmp???

Post by tores »

I have done some small tests using === and strcmp(), and they gave the same results on the same strings... Personally I think it's a lot easier to use === instead of strcmp, but since strcmp is available I guess it is more secure than ordinary comparison. Is there some cases where the === operator will fail, and strcmp not?

Regards tores
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

well strcmp can return < or > as well as 0 if they are equal. so it offers more functionality than == or ===

but i rarely use it, if your just checking if its the same or not, === or !== is what i usually use.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

with strcmp is that you the risk for a typo is smaller...

everybody will type = instead == or === some day...
Post Reply