I know it's not exactly the answer, though if I understood correctly what you are trying to achieve, I would not use the "position" inside a path to decide that, but I would use a kind of placeholder, for example:
$url = 'something/group/my_group';
$p = explode('/', $url);
$group = '';
$get_group = false;
foreach ($p => $d)
{
if ($get_group === true)
{
$group = $d;
break;
}
if ($d === 'group')
{
$get_group = true;
}
}
or alternatively:
$url = 'something/group-my_group';
$p = explode('/', $url);
$group = '';
foreach ($p => $d)
{
if (substr($d, 0, 5) === 'group')
{
$group = substr($d, 6);
}
}
this would work somehow like an indexed array, so that you know what you are dealing with is actually what you are supposed to (and not maybe a wrong url).
Added missing code tag ... spuds