Jump to content

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


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.

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.