Last Item Foreach


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <?php
  2. $array = array('apples','bananas','cranberries','durians');
  3. $last_item = end($array);
  4.  
  5. foreach($array as $item) {
  6. if ($item == $last_item) {
  7. print "I like to eat " . $item;
  8. }
  9. }
  10. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.