Jump to content

[SOLVED] Help With Line of Code - Please! :-)


smkied

Recommended Posts

Hello!

 

I have this piece of code:

 

if ($_POST['item1_price']!=8.95)    $next_payment='2012-01-01 00:00:00';

 

It's for payment gateway. Anyhow, all i need to figure out how to do is I need to have more than one value where you see "8.95". So basically, I want the code to say that if the price is not equal to 8.95, 11.95, 14.95 then set the next payment to 2012.

 

Is there a simple way to just add more numbers to that line? I didn't write the code so I don't know, but I do know that if there is a way to do this then I won't need to edit anything anywhere else.

 

Any help is greatly appreciated. Thanks!!

 

Link to comment
https://forums.phpfreaks.com/topic/129494-solved-help-with-line-of-code-please/
Share on other sites

That was quick, thanks! I don't mean to be overstepping your generosity, but I'm really "white" when it comes to PHP code, so although I almost sort of get what's going on with this array code, I can't quite figure out how I would adapt it to my line of code.

 

Could you perhaps throw down an example for me??

$prices = array(8.95, 11.95, 14.95);  //create an array of your prices.

//then just check if the price is in the array, or NOT in the array in your case

if(!in_array($_POST['item1_price'], $prices)) {
    $next_payment='2012-01-01 00:00:00';
}

The format is:

in_array($needle, $haystack)

where needle is what you are searching for and haystack is the array of values to search against.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.