Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //using end() function to find last array key changes the array pointer, which can cause problems.
- $array = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 2);
- // Get array keys
- $arrayKeys = array_keys($array);
- // Fetch last array key
- $lastArrayKey = array_pop($arrayKeys);
- //iterate array
- foreach($array as $k => $v) {
- if($k == $lastArrayKey) {
- //during array iteration this condition states the last element.
- }
- }
- ?>
Add Comment
Please, Sign In to add comment