if strcmp fail?

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
Cirdan
Forum Contributor
Posts: 144
Joined: Sat Nov 01, 2008 3:20 pm

if strcmp fail?

Post by Cirdan »

I have this if statement, which fails when the mode is "reply". It works fine if the mode is "thread". I can't see the reason why it would fail.

Code: Select all

if(strcmp($this->_mode, 'thread') < 0 || strcmp($this->_mode, 'reply') < 0) {
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: if strcmp fail?

Post by requinix »

strcmp returns something <0 if the first argument is less than the second. You'd want ==0 or !=0...

...if there was any point in using strcmp in the first place. PHP isn't C or Java: you can compare strings just fine.

Code: Select all

if($this->_mode == "thread" || $this->_mode == "reply") {
Cirdan
Forum Contributor
Posts: 144
Joined: Sat Nov 01, 2008 3:20 pm

Re: if strcmp fail?

Post by Cirdan »

Okay, the problem was I should have been using && not ||, and should have been using !=

EDIT: thanks!
Post Reply