Advertisement
badlogic

Getting the key of the end of an array

Jul 13th, 2016
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.34 KB | None | 0 0
  1. <?php
  2.  
  3. //usefull for deleting dynamic input
  4.  
  5. $array = array(
  6.     '0' => 123,
  7.     '1' => 456,
  8.     '2' => 789,
  9.     '3'=> 1111,
  10. );
  11.  
  12. $te = end($array);         // move the internal pointer to the end of the array
  13. $key = key($array);  // fetches the key of the element pointed to by the internal pointer
  14.  
  15. var_dump($key);
  16. var_dump($te);
  17. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement