smkied Posted October 22, 2008 Share Posted October 22, 2008 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!! Quote Link to comment https://forums.phpfreaks.com/topic/129494-solved-help-with-line-of-code-please/ Share on other sites More sharing options...
AndyB Posted October 22, 2008 Share Posted October 22, 2008 in_array() might be helpful -> http://ca.php.net/manual/en/function.in-array.php Quote Link to comment https://forums.phpfreaks.com/topic/129494-solved-help-with-line-of-code-please/#findComment-671345 Share on other sites More sharing options...
smkied Posted October 22, 2008 Author Share Posted October 22, 2008 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?? Quote Link to comment https://forums.phpfreaks.com/topic/129494-solved-help-with-line-of-code-please/#findComment-671347 Share on other sites More sharing options...
smkied Posted October 22, 2008 Author Share Posted October 22, 2008 I was just suggested this piece of code: if ($_POST['item1_price']!=8.95 && $_POST['item1_price']!=11.95 && $_POST['item1_price']!=14.95) { $next_payment='2012-01-01 00:00:00'; } Will that work? Quote Link to comment https://forums.phpfreaks.com/topic/129494-solved-help-with-line-of-code-please/#findComment-671357 Share on other sites More sharing options...
AndyB Posted October 22, 2008 Share Posted October 22, 2008 Will that work? No. Look at the logic and see what happens if item1_price is 8.95. Quote Link to comment https://forums.phpfreaks.com/topic/129494-solved-help-with-line-of-code-please/#findComment-671381 Share on other sites More sharing options...
CroNiX Posted October 22, 2008 Share Posted October 22, 2008 $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. Quote Link to comment https://forums.phpfreaks.com/topic/129494-solved-help-with-line-of-code-please/#findComment-671383 Share on other sites More sharing options...
smkied Posted October 22, 2008 Author Share Posted October 22, 2008 ah nice, that's very slick. Thank you very much! Makes sense too, maybe one day I'll manage to learn PHP.... one day.... Quote Link to comment https://forums.phpfreaks.com/topic/129494-solved-help-with-line-of-code-please/#findComment-671385 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.