-11

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

4
  • i don't see any or in your code. Commented Oct 25, 2016 at 9:59
  • Show us what you have tried and why they didn't work / What errors you got. Commented Oct 25, 2016 at 9:59
  • Be specific to your question ! Commented Oct 25, 2016 at 9:59
  • 2
    For future reference: How to ask a question Commented Oct 25, 2016 at 11:03

3 Answers 3

2

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)): ?>
Sign up to request clarification or add additional context in comments.

1 Comment

Please, don't reward bad questions with answers.
1
<?php if( ( $CURRENT_USER['selected_plan_id'] == '4') || ( $CURRENT_USER['selected_plan_id'] == '5') || ( $CURRENT_USER['selected_plan_id'] == '6') ) : ?>

This will look to see if the $CURRENT_USER['selected_plan_id'] is 4 or 5 or 6

7 Comments

Please, don't reward bad questions with answers.
From your own profile - "I'm developer and find myself at SO both to help other people but also to learn from others, both by asking and by reading other peoples questions." - I see no issue in assisting others.
I help people who follow SO's standard and rule set, there's no effort shown here, further more, this isn't advanced php or complex logic, it's some of the more basic things that can easily be researched.
I disagree it can be easily researched, I've been searching for over an hour and every OR example I've tried with my code does not work. Apologies but I didn't include what I tried as none of it worked (so didn't see the point). Some of the ones I tried are there now
Unfortunately not everyone will go looking for rules every time they enter a website, they just want to know the answers.
|
0

My instinct would lead me to in_array() because it seems to be a simpler way to express the idea.
Here are the man pages for the "or" operator. http://php.net/manual/en/language.operators.logical.php http://php.net/manual/en/language.operators.precedence.php

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.