Views Contextual filter: php code for getting the value from url
Though the solution you have implemented worked but my suggestion is to use the request_uri() instead of the $_SERVER['REQUEST_URI'] because of the following reasons:


$_SERVER['REQUEST_URI'] is only available on Apache, whereas request_uri() generate an equivalent using other environment variables.
Apache does nothing by default to sanitize the $_SERVER variables so directly using it without passing through the check_plain should be considered unsafe.


So its better to get the URL like this:


  $current_url = check_plain(request_uri());


Example: if the url is http://www.example.com/param1/param2/param3 than the $current_url will contain /param1/param2/param3. 

Rest you can build the logic to get the last params, there are numerous ways of doing that.