Guest User

Untitled

a guest
Dec 13th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.30 KB | None | 0 0
  1. $arr = ['a' => 'Alice', 'b' => 'Bob'];
  2.  
  3. # 今まで(ポインタが移動しちゃう)
  4. end($arr);
  5. # => "Bob"
  6.  
  7. # 存在チェックが必要なのでこれはこれで長い。いい方法あるかな?
  8. $lastkey = array_key_last($arr);
  9. array_key_exists($lastkey, $arr) ? $arr[$lastkey] : null
  10. # => "Bob"
Add Comment
Please, Sign In to add comment