PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
Copy Clear
Copy Format Clear
<?php function getIn($data, $arrsearch) { $result = null; if (empty($data)) return $result; for ($i = 0; $i < count($arrsearch); $i++) { if (is_int($arrsearch[$i])) { $result[] = "[".$arrsearch[$i]."]"; } else { $result[] = "['".$arrsearch[$i]."']"; } } $resulttext = implode('', $result); var_dump($data$resulttext); if (!array_key_exists($data.$resulttext, $data)) { return null; } return $result; } $data = [ 'user' => 'ubuntu', 'hosts' => [ ['name' => 'web1'], ['name' => 'web2', null => 3, 'active' => false] ] ]; var_dump(getIn($data, ['hosts', 1, 'name'])); // 'ubuntu')
Show:  
Copy Clear