I have a line of code like
$qs = explode('&',$_SERVER['QUERY_STRING']);
$pid = explode('=',$qs[1]);
this will return something such as array(2) { [0]=> string(5) "cPath" [1]=> string(14) "70_229_242_240" }
I then have
$cat_ID = explode('_',$pid[1]);
which returns array(4) { [0]=> string(2) "70" [1]=> string(3) "229" [2]=> string(3) "242" [3]=> string(3) "240" }
Using
print_r($cat_ID[3]);
i can get the final value of 240.
However, this only works in instances where the original string is made up of four numbers separated by underscores. In some circumstances i may have a string of three, two or even one number.
Is there a simple way to make it always fetch the last number in the string without having to code a bunch of if statements to cover situations where $cat_ID[3] or $cat_ID[2] would be empty/non existant?
I suspect the
$pid = explode('=',$qs[1]);
can be changed to take the numbers following the last underscore, but i break it every time i try.