あまりきれいではありませんが(再帰的でもありません。これは良いことです)、動作するはずです。
// Input data
$array = array(
"collection" => "departments",
"action" => "find",
"args" => array ("_id" => array('$in' => "{{variablename}}"))
);
// Create a stack
$stack = array(&$array);
// Loop until the stack is empty
while (sizeof($stack) > 0) {
// Get the first variable in the stack (by reference)
foreach ($stack as &$current) break;
// Remove the first variable from the stack (by reference, same as array_shift but array_shift breaks the references)
$stack = array_slice($stack, 1);
// If the shifted variable is an array
if (is_array($current)) {
// Add all the array's values to the stack (by reference)
foreach ($current as &$value) {
$stack[] =& $value;
}
}
// If the shifted variable is the one we want
elseif ($current == '{{variablename}}') {
// Stop the loop, leaving $current as the reference to the variable we want
break;
}
}
$current = 'test';
var_dump($current);
var_dump($array);
例: http: //ideone.com/hEzZk