Guest User

Untitled

a guest
Feb 24th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. <?php
  2. //using end() function to find last array key changes the array pointer, which can cause problems.
  3.  
  4. $array = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 2);
  5. // Get array keys
  6. $arrayKeys = array_keys($array);
  7. // Fetch last array key
  8. $lastArrayKey = array_pop($arrayKeys);
  9. //iterate array
  10. foreach($array as $k => $v) {
  11. if($k == $lastArrayKey) {
  12. //during array iteration this condition states the last element.
  13. }
  14. }
  15. ?>
Add Comment
Please, Sign In to add comment