Forum Moderators: coopster

Message Too Old, No Replies

change value of 0

         

th1chsn

6:25 am on Aug 10, 2008 (gmt 0)

10+ Year Member



I want to check a variable to see if it's a zero and if it is change it to a 1. But there must be something wrong with my code because it isn't changing the value.


$id = 0;
if ($id = 0) {
$id = 1;
}
echo $id;

Can someone help me figure out what I'm doing wrong?

th1chsn

6:30 am on Aug 10, 2008 (gmt 0)

10+ Year Member



Figured it out. You guys are good. You don't even have to answer the posts :)


if ($id == '0') {
$id = 1;
}

coopster

3:58 pm on Aug 13, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



LOL!
Yep, a common mistake and easy to overlook!

eeek

11:27 pm on Aug 13, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Still not quite right. The quotes around the zero, while they do work due to loose typing, are causing the zero to be a string.