Ответ 1
Здесь простое решение. Вместо того, чтобы передавать строку для индексов, вы передаете массив.
public function getIndexValue(array $indexes) {
// count the # of indexes we have
$count = count($indexes);
// local reference to data
$data = $this->array_data;
for ($i = 0; $i < $count; $i++)
{
// enter the array at the current index
$data = $data[$indexes[$i]];
}
return $data;
}
А затем вместо строки вы передадите массив:
$MyClass->getIndexValue(['first', 'a'])