3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = json_decode('{ "name": "", "type": "layout", "children": [ { "name": "", "type": "section", "children": [ { "name": "", "type": "row", "children": [ { "name": "", "type": "column", "props": { }, "children": [] }, { "type": "column", "children": [ { "type": "itemdata", "props": { "basevalue": "100" }, "children": [] } ] } ] } ] }]}',true); //print_r($arr); function getBaseValue($arr,$search_key){ $pending_calls = []; foreach($arr as $key => $value){ if(is_array($value)){ $pending_calls[] = $value; }else if($search_key === $key){ return $value; } } foreach($pending_calls as $call){ $returned_val = getBaseValue($call,$search_key); if($returned_val !== false) return $returned_val; } return false; } echo getBaseValue($arr,'basevalue');

preferences:
24.96 ms | 404 KiB | 5 Q