带有不同数字的未定义偏移量

I am trying to explode some links, but some of them contain 7 / and some of them have 6 / Therefor I get error Notice: Undefined Offset 7, how can I overcome this:

$imagethumb = array('6 slashes in url','7 slashes'); // this is just for simulating
$imagethumbs = explode('/', $imagethumb);
$thumbname = $imagethumbs[7];

Always choose the latest entry in the array.

You can count the amount of indexes using the count() function.

You code should look like this: $thumbname = $imagethumbs[count($imagethumbs) - 1];

Try with isset like

$thumbname = $imagethumbs[6];
if(isset($imagethumbs[7])) {
    $thumbname = $imagethumbs[7];
}

Or even you can try like

$thumbname = $imagethumbs[count($imagethumbs)-1];