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

ตอนนี้สมมติว่าเรามีบล็อก else ด้วย:

html<?php if ($test) { ?>
  <p>+++</p>
<?php } else { ?>
  <p>---</p>
<?php } ?>

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

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

กำหนดตัวแปร:

html<?php
  $show = true;
?>

กำหนดโค้ด:

html<div>
  <p>text+</p>
  <p>text+</p>
  <p>text+</p>
</div>
<div>
  <p>text-</p>
  <p>text-</p>
  <p>text-</p>
</div>

ให้แสดง div แรก ถ้าตัวแปร show มีค่าเท่ากับ true และแสดง div ที่สอง ถ้าตัวแปร มีค่าเท่ากับ false