[thelist] PHP - Simple one

Anthony Baratta Anthony at Baratta.com
Fri Oct 12 22:29:43 CDT 2001


At 08:18 PM 10/12/2001, you wrote:
>Must be tired.  I can't seem to get this one to work right.   Should be 
>really simple.  If there is a match, I need it to give 5 points.  However, 
>it is concatenating the variables together instead of adding it.  Any tips?
>
>Chris
>
>$points = 0;
>
>if($correct[0] == '1'){ // We have a match
>      $points = $points + 5;
>}
>
>echo $points;
>
>Should return something like 10 or 20.  Instead it returns 510152025.

That makes no sense, and I'm not tired. ;-)

What version of PHP are you using?

http://www.php.net/manual/en/language.types.type-juggling.php

says that it should work the way you are expecting. You might want to force 
$points to be an Integer, with $points = intval($points) = 5;

Good Luck.


---
Anthony Baratta
President
Keyboard Jockeys

"Conformity is the refuge of the unimaginative."





More information about the thelist mailing list