3v4l.org

run code in 300+ PHP versions simultaneously
<?php function searchFromArray($array, $keyword) { echo "\n".$keyword."\n"; $result = array(); if (count($keyword) == 2) { $result[] = $array[$keyword[0]]; } else { foreach ($keyword as $kw => $vw) { if (isset($array[$vw])) { if (is_array($array[$vw])) { unset($keyword[0]); searchFromArray($array[$vw], $keyword); } else { $result[] = $array[$vw]; } } } } return $result; } $array_search = array( 'offset' => '', 'count' => '', 'max_count' => '', 'content_list' => array(array( 'content' => array( 'id'=>'1', 'type'=>'', 'name_title'=>'', 'parent_id'=>'', 'rating_type'=>'', 'link_url'=>'', 'tag' => array( 'id' => 'tag_id_1', 'name' => 'tag_name_1' ), 'image_dir'=>'', 'image_url'=>'', 'image_dir_thumb'=>'x', 'image_url_thumb'=>'' ), 'content' => array( 'id'=>'2', 'type'=>'', 'name_title'=>'', 'parent_id'=>'', 'rating_type'=>'', 'link_url'=>'', 'tag' => array( 'id' => 'tag_id_2', 'name' => 'tag_name_2' ), 'image_dir'=>'', 'image_url'=>'', 'image_dir_thumb'=>'y', 'image_url_thumb'=>'' ) ) ) ); $keyword = array('content_list', 'content', 'tag'); $result = searchFromArray($array_search, $keyword); var_dump($result);
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Warning: Array to string conversion in /in/UPO8P on line 4 Array Warning: Array to string conversion in /in/UPO8P on line 4 Array Warning: Undefined array key 0 in /in/UPO8P on line 8 Warning: Undefined array key "" in /in/UPO8P on line 8 array(0) { }
Output for 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.8 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.31, 7.4.0 - 7.4.33
Notice: Array to string conversion in /in/UPO8P on line 4 Array Notice: Array to string conversion in /in/UPO8P on line 4 Array Notice: Undefined offset: 0 in /in/UPO8P on line 8 Notice: Undefined index: in /in/UPO8P on line 8 array(0) { }
Output for 7.3.32 - 7.3.33
Array Array array(0) { }
Output for 5.3.0 - 5.3.29
Array Array Notice: Undefined offset: 0 in /in/UPO8P on line 8 Notice: Undefined index: in /in/UPO8P on line 8 array(0) { }
Output for 4.3.0 - 4.3.11, 4.4.0 - 4.4.9, 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17
Array Array Notice: Undefined offset: 0 in /in/UPO8P on line 8 Notice: Undefined index: in /in/UPO8P on line 8 array(0) { }

preferences:
223.56 ms | 403 KiB | 310 Q