The unexplained!

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
spacebiscuit
Forum Contributor
Posts: 390
Joined: Mon Mar 07, 2005 3:20 pm

The unexplained!

Post by spacebiscuit »

Can anyone expalin this:

Code: Select all

echo $_SESSION[price];
$_SESSION[price]=$_SESSION[price]*2;
echo $_SESSION[price];
Output:

1,210.58
2

Why is session[price] losing its value?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: The unexplained!

Post by Celauran »

The comma ensures it's being treated as a string and giving it an intval() of 1. Strip the comma and everything works as expected.
spacebiscuit
Forum Contributor
Posts: 390
Joined: Mon Mar 07, 2005 3:20 pm

Re: The unexplained!

Post by spacebiscuit »

Grrrr, thanks!
Post Reply