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++) { $result[] = "['".$arrsearch[$i]."']"; } $resulttext = implode('', $result); $result = $data$resulttext; 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