How to pass 0 as a number, not null (PHP)?

Soldato
Joined
27 Dec 2005
Posts
17,296
Location
Bristol
I've got an array that lists prices, and one is "0", ie free. The code checks if there's a discount later by checking the price, and obviously it reads 0 and therefore thinks there isn't a discount and charges full price.

Shortened code:

PHP:
$postedcode = $_POST['code'];
$codelist = array("COUPONCODE" => "0");
$discountlist = array("50" => "SECRETCODE", "0" => "SECRETCODE2");

$discount = $codelist[$postedcode];

if(!$discount){
// charge full price
} else {
// charge discount price
}

How can I pass this through as a number rather than it being seen as null? Thanks!
 
Soldato
OP
Joined
27 Dec 2005
Posts
17,296
Location
Bristol
That will set it as null as well, no?

I actually can't do this anyway as the end system (PayPal) can't deal with things for free! But, I'd still be interested to hear how you can do this anyway.
 
Back
Top Bottom