# difference between <= and =

Page 1 of 1

## 8 Replies - 735 Views - Last Post: 21 September 2012 - 08:02 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=292763&amp;s=ba472a7795a2eed36f0a0a81af2151a7&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 iheartbreakz

• D.I.C Head

Reputation: 1
• 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

• Games, Graphs, and Auctions

Reputation: 12276
• Posts: 45,364
• 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

• D.I.C Head

Reputation: 1
• 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

• Games, Graphs, and Auctions

Reputation: 12276
• Posts: 45,364
• 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

• Saucy!

Reputation: 6246
• Posts: 24,014
• 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

• Hash != Encryption

Reputation: 931
• Posts: 3,216
• 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

• Enhance Your Calm

Reputation: 4240
• Posts: 7,216
• 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

• D.I.C Head

Reputation: 1
• 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

• I wrote you an code

Reputation: 1266
• Posts: 4,064
• Joined: 12-May 09

## Re: difference between <= and =

Posted 21 September 2012 - 08:02 PM

iheartbreakz, 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

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }