superhappybunnycat superhappybunnycat - 1 month ago 6
PHP Question

PHP if statement with OR operators

I'm using the below statement on my website. I want to be able to say if the selected_plan_id is 4, 5, OR 6. Any of the OR variations I use break my code.

<?php if($CURRENT_USER['selected_plan_id'] == '5'): ?>


Here's the ones I tried so far:

<?php if($CURRENT_USER['selected_plan_id'] == '5' or '4' or '6'): ?>


:( error

<?php if($CURRENT_USER['selected_plan_id'] == '"5", "4", "6"'): ?>


:( displayed this for every user

<?php if($CURRENT_USER['selected_plan_id'] == '5'): or if($CURRENT_USER['selected_plan_id'] == '4'): or if($CURRENT_USER['selected_plan_id'] == '6'): ?>


:( error

Answer

Use || statement.

<?php if($CURRENT_USER['selected_plan_id'] == '4' || $CURRENT_USER['selected_plan_id'] == '5' || $CURRENT_USER['selected_plan_id'] == '6'): ?>

Or

Use in_array().

$arr = Array (4,5,6);
<?php if(in_array($CURRENT_USER['selected_plan_id'],$arr)): ?>