Advertisement
karlakmkj

Loop shorthand

Sep 20th, 2021
1,005
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.48 KB | None | 0 0
  1. <h1>Only Shoes Shoe Shop</h1>
  2. <?php
  3. for ($i = 0; $i < 5; $i++){  // <-- remove and put :
  4. ?>
  5. <p>We sell shoes</p>
  6. <?php
  7. } // <-- remove and put endfor;
  8. ?>
  9.  
  10. <h1>Shoe Shop</h1>
  11. <?php
  12. $footwear = [
  13.   "sandals" => 4,
  14.   "sneakers" => 7,
  15.     "boots" => 3
  16. ];
  17. ?>
  18. <p>Our footwear:</p>
  19. <?php
  20. foreach ($footwear as $type => $brands):
  21. ?>
  22. <p>We sell <?=$brands?> brands of <?=$type?></p> //because this is in HTML mode, have to use <?= $variable ?> for variables
  23. <?php
  24. endforeach;
  25. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement