Jump to content

Recommended Posts

	echo "$_SESSION[totalcost] <br>";
	echo "$_SESSION[funds] <br>";
	IF ( $_SESSION[funds] < $_SESSION[totalcost] ) {
		echo "You do not have enough cash to upgrade <br>";
	} ELSE {
		echo "Upgrading... <br>";
	}	

 

Output:

 

75,000

622,500

You do not have enough cash to upgrade

 

I have no idea why. What reasons could it be?

Link to comment
https://forums.phpfreaks.com/topic/50679-numeric-comparing-giving-wrong-answer/
Share on other sites

ok will try that.

 

however, i got it to work by removing the

 

	echo "$_SESSION[totalcost] <br>";
	echo "$_SESSION[funds] <br>";

 

statements, as a PHP Expert (you seem to be answering everyones questions with ease) why could this be?!

 

[edit]

your way worked. hm i deleted a few statements and it didnt work again, so used yours, and harruh!

Chances are it could be a notice conflict. Because you are essentially using constants to reference the index of the array. I would highly suggest you steer away from that and echo it out like so:

 

<?php
echo $_SESSION['totalcost'] ." <br>";
echo $_SESSION['funds'] . " <br>";
?>

 

The way above will overall be more efficient and correct. This way no notice is thrown for using an undefined constant. Essentially what happens right now, if you user funds without single quotes to try and grab an object at that index of the array the code first searchs to check to see if there is a constant called "funds" if not than it just assumes the word.

 

Anyhow maybe give that a test and see if that works.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.