Take the last exploding position

Asked

Viewed 831 times

2

Guys need to get the last position after giving a explode. How do I do?

 $geturl = explode('/', $_SERVER['REQUEST_URI']);

 self::$modulo = isset($geturl[2]) ? $geturl[2] : '';
 self::$funcao = isset($geturl[3]) ? $geturl[3] : '';
 self::$chave = isset($geturl[4]) ? $geturl[4] : '';

Note: It can happen from $chave be void

1 answer

6


Use the function end() to leave the array pointer at the last position and get its value.

$ultimo = end($geturl);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.