3v4l.org

run code in 300+ PHP versions simultaneously
<?php $IVR = array( "TagName:IVRCode" => array( "ExecApp:IVRCode" => array( "value" => "123456789" ), ), "TagName:SetLangSP" => array( "ExecApp:SetLang" => array( "value" => "ES" ), ), "TagName:Answer" => array( "ExecApp:Answer" => array( "value" => "" ), ), "TagName:PlayGreeting" => array( "ExecApp:Play" => array( "AudioValue" => "Audio-Greeting.${lang}", "AudioType" => "wav" ), ), "TagName:Menu1" => array( "ExecApp:PressMenu" => array( "MaxDigits" => "5", "TimeOut" => "3500", "AudioSource" => "AudioWav", "Type" => "Wav", "Invalid_Option" => array( "ExecApp:Play" => array( "AudioValue" => "Audio-Please-Type-A-Valid-Option.${lang}", "AudioType" => "wav" ), "ExecApp:GoTo" => array( "Value" => "Menu1" ), ), "TimeOut_Option" => array( "ExecApp:Play" => array( "AudioValue" => "Audio-Please-Type-A-Valid-Option.${lang}", "AudioType" => "wav" ), "ExecApp:GoTo" => array( "Value" => "Menu1" ), ), "Tree_Options" => array( "0:Operadora" => array( "ExecApp:Play" => array( "AudioValue" => "Audio-Wait-While-We-Transfer.${lang}", "AudioType" => "wav" ), "ExecApp:Transfer" => array( "Value" => "13626" ), ), "1:Ventas" => array( "ExecApp:Play" => array( "AudioValue" => "Audio-Wait-While-We-Transfer.${lang}", "AudioType" => "wav" ), "ExecApp:Transfer" => array( "Value" => "13626" ), ), "2:Servicio al cliente" => array( "ExecApp:Play" => array( "AudioValue" => "Audio-Wait-While-We-Transfer.${lang}", "AudioType" => "wav" ), "ExecApp:Transfer" => array( "Value" => "13626" ), ), "3:Soporte Tecnico" => array( "ExecApp:PressMenu" => array( "MaxDigits" => "5", "TimeOut" => "3500", "AudioSource" => "AudioWav", "Type" => "Wav", "Tree_Options" => array( "0:Television" => array( "ExecApp:Play" => array( "AudioValue" => "Audio-Wait-While-We-Transfer.${lang}", "AudioType" => "wav" ), "ExecApp:Transfer" => array( "Value" => "13626" ), ), "1:Internet" => array( "ExecApp:Play" => array( "AudioValue" => "Audio-Wait-While-We-Transfer.${lang}", "AudioType" => "wav" ), "ExecApp:Transfer" => array( "Value" => "13626" ), ), "2:Telefonia" => array( "ExecApp:Play" => array( "AudioValue" => "Audio-Wait-While-We-Transfer.${lang}", "AudioType" => "wav" ), "ExecApp:Transfer" => array( "Value" => "13626" ), ), "9:Previous Menu" => array( "ExecApp:Play" => array( "AudioValue" => "Audio-Wait-While-We-Transfer.${lang}", "AudioType" => "wav" ), "ExecApp:GoTo" => array( "Value" => "Menu1" ), ), ), ), ), ), ), ), ); echo '<pre>' . print_r($IVR,1) . '</pre>'; echo '<pre>' . print_r(goToTag($IVR, "2:Telefonia"),1) . '</pre>'; echo printAll($IVR); function printAll($a) { if (!is_array($a)) { echo $a, ' '; return; } foreach($a as $v) { printAll($v); } } function goToTag($array, $index) { $queue = array($array); while (($item = array_shift($queue)) !== null) { if (!is_array($item)) continue; if (isset($item[$index])) return $item[$index]; $queue = array_merge($queue, $item); } return null; } echo "-****-<br>"; $iterator = new RecursiveArrayIterator($IVR); iterator_apply($iterator, 'navigateArray', array($iterator)); function navigateArray($iterator) { while ($iterator->valid()) { if ($iterator->hasChildren()) { navigateArray($iterator->getChildren()); } else { printf("%s: %s ", $iterator->key(), $iterator->current()); } $iterator->next(); } } ?>

preferences:
53.76 ms | 402 KiB | 5 Q