如何使用 PHP RecursiveIteratorIterator 解决以下问题?
$arr = array(
"sum"=>array(2,4,6, "multiply" => array(1,3,5) ),
"multiply"=>array(3,3,3, "sum" => array(2,4,6) ),
);
我期待以下答案
(2 + 4 + 6 + ( 1 * 3 * 5) ) = 27;
(3 * 3 * 3 * (2 + 4 + 6)) = 324;
到目前为止的部分代码..
$calc = new ArrayObject($arr);
$MRI = new RecursiveIteratorIterator(new MyRecursiveIterator($calc), 1);
foreach ($MRI as $key=>$value) {
echo " Current Depth: ". $MRI->getDepth() . "\n";
echo $key . " : " . $value . "\n";
$currentDepth = $MRI->getDepth();
for ($subDepth = $currentDepth; $subDepth >= 0; $subDepth--)
{ echo "sub Depth: ". $subDepth . "\n";
$subIterator = $MRI->getSubIterator($subDepth);
// var_dump($subIterator); } }