php – Need help with misunderstanding If else;

Question:

The code is as follows:

1 <?php if (!empty(res['$pre'])): ?>BLABLA<?php endif; ?>

2. <?php if (empty(res['$press'])): ?>TEST<?php else: ?>TEST2<?php endif; ?>

Okay, if $ press is empty, TEST2 is shown, but TEST2 is shown in the 1st if.

Why? After all, I'm closing with <?php endif; ?> first.

Answer:

Because you are writing 2 if , not if else . You write если and если .

Your condition does not contradict each other.

<?php if (empty($press)): ?>
  TEST
<?php  elseif(empty($press2)): ?>
  TEST2
 <?php endif; ?>
Scroll to Top