3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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 5.4.0 - 7.3.0beta1
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 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 - 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) { }