8 Replies - 354 Views - Last Post: 21 September 2012 - 08:02 PM Rate Topic: -----

#1 iheartbreakz  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 196
  • Joined: 27-April 11

difference between <= and =

Posted 21 September 2012 - 03:47 PM

Can anyone tell me the difference between these 2 functions
if($this->itemCount <= 0) and if($this->itemCount = 0)


both of them are giving me different results but wouldn't <= 0 and = 0 mean the same thing?
Is This A Good Question/Topic? 0
  • +

Replies To: difference between <= and =

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10558
  • View blog
  • Posts: 39,064
  • Joined: 27-December 08

Re: difference between <= and =

Posted 21 September 2012 - 03:50 PM

The = operator is for assignments, and the == operator is for comparisons. Mathematically, less than or equal to has a different meaning than equal to. The meanings are pretty obvious.
Was This Post Helpful? 1
  • +
  • -

#3 iheartbreakz  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 196
  • Joined: 27-April 11

Re: difference between <= and =

Posted 21 September 2012 - 03:53 PM

yea i knew that but my question is wouldnt <= mean less than OR equal to?
Was This Post Helpful? 0
  • +
  • -

#4 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10558
  • View blog
  • Posts: 39,064
  • Joined: 27-December 08

Re: difference between <= and =

Posted 21 September 2012 - 03:56 PM

Yes, that is correct.
Was This Post Helpful? 0
  • +
  • -

#5 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6062
  • View blog
  • Posts: 23,513
  • Joined: 23-August 08

Re: difference between <= and =

Posted 21 September 2012 - 04:37 PM

if($this->itemCount <= 0) and if($this->itemCount = 0)


That code is not even valid code.
Was This Post Helpful? 0
  • +
  • -

#6 creativecoding  Icon User is offline

  • Hash != Encryption
  • member icon


Reputation: 926
  • View blog
  • Posts: 3,205
  • Joined: 19-January 10

Re: difference between <= and =

Posted 21 September 2012 - 04:46 PM

What part about that isn't valid code?
Was This Post Helpful? 0
  • +
  • -

#7 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3718
  • View blog
  • Posts: 5,990
  • Joined: 08-June 10

Re: difference between <= and =

Posted 21 September 2012 - 05:00 PM

The and would be invalid in that position, although I suspect that was more for our benefit than meant to represent actual code.
Was This Post Helpful? 0
  • +
  • -

#8 iheartbreakz  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 196
  • Joined: 27-April 11

Re: difference between <= and =

Posted 21 September 2012 - 07:52 PM

lol i asked it as a question ... shoulda put 2 [code] tags there.. sorry
Was This Post Helpful? 0
  • +
  • -

#9 xclite  Icon User is offline

  • LIKE A BOSS
  • member icon


Reputation: 904
  • View blog
  • Posts: 3,165
  • Joined: 12-May 09

Re: difference between <= and =

Posted 21 September 2012 - 08:02 PM

View Postiheartbreakz, on 21 September 2012 - 06:53 PM, said:

yea i knew that but my question is wouldnt <= mean less than OR equal to?

What macosxnerd101 is saying is that your second condition will always have the same result, because it sets the value to 0. It has the same result as writing
$this->itemCount = 0
if ($this->itemCount)


While the first actually compares the value, which will return true or false depending on whether the value is less than or equal to 0 or greater than 0.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1