บล็อก elseif ในเงื่อนไขสำหรับการแยกโค้ด PHP

คุณยังสามารถสร้างเงื่อนไขหลายๆ อันได้ด้วย elseif:

html<?php if ($test === 1) { ?>
  <p>1</p>
<?php } elseif ($test === 2) { ?>
  <p>2</p>
<?php } else { ?>
  <p>?</p>
<?php } ?>

มาเขียนใหม่ด้วยไวยากรณ์แบบอื่น:

html<?php if ($test === 1): ?>
  <p>1</p>
<?php elseif ($test === 2): ?>
  <p>2</p>
<?php else: ?>
  <p>?</p>
<?php endif; ?>
Задание 1

ให้ div ดังนี้:

html<div>
  <p>text1</p>
  <p>text1</p>
  <p>text1</p>
</div>
<div>
  <p>text2</p>
  <p>text2</p>
  <p>text2</p>
</div>
<div>
  <p>text-</p>
  <p>text-</p>
  <p>text-</p>
</div>

สร้างเงื่อนไขที่จะแสดง div อันใดอันหนึ่ง