для этого узкого примера как-то так:
$array = array(
'one' => 'hi',
'two' => 'privet',
'three' => array('three_1' => 'hi', 'three_2' => 'privet'),
);
$str = 'three|three_1';
$keys = explode("|", $str);
var_dump($array[$keys[0]][$keys[1]]);
Updated 1:<?php
function foo($array, $str){
$keys = explode('|', $str);
$keysCount = count($keys);
$result = $array;
for($i = 0; $i < $keysCount; $i++){
if(!is_array($result) && $i < ($keysCount - 1)){
throw new Exception("Array depth not expected");
}
if(!isset($result[$keys[$i]])){
throw new Exception(sprintf("Key '%s' not found", $keys[$i]));
}
$result = $result[$keys[$i]];
}
return $result;
}
$array = array(
'one' => 'hi',
'two' => 'privet',
'three' => array('three_1' => 'hi', 'three_2' => 'privet'),
);
$str = 'three|three_1';
var_dump(foo($array, $str));