0

I have a problem with an if loop with more than one condition inside I bring an example to understand:

for example let's say we have 3 fields in the same database table

one

two

three

each of these 3 fields has 3 states

empty

on hold

ready

I want to see a statement only when all 3 are up ready

    <?php if($collaboratore_abilitato['one'] === 'ready'|| $collaboratore_abilitato['two'] === 'ready' || $collaboratore_abilitato['three'] === 'ready') :?>

<!-- SHOW CODE -->

<?php else: ?>

<!-- SHOW ANTOHER CODE -->


    <?php endif; ?>

and

$collaboratore_abilitato

it s a paramater for a while

my problem is that when I activate the 3 parameter it shows me the contents of show code and not of show another code

I don't understand why it should show me show another code only when the 3 statements are verified in ready

1
  • 1
    || means if any are ready, you may want && to check that they are all ready Commented Oct 30, 2020 at 17:12

1 Answer 1

1

You should change || to && for check that they are all ready

<?php 
      if (
           $collaboratore_abilitato['one'] === 'ready' &&
           $collaboratore_abilitato['two'] === 'ready' &&
           $collaboratore_abilitato['three'] === 'ready' 
         ): 
?>

    <!-- SHOW CODE -->

<?php else: ?>

    <!-- SHOW ANTOHER CODE -->

<?php endif; ?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.