3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $a = array('hi' => 'there', 'there' => 'world'); function dgs_Aval($array, $keys) { // return first valid value of array[key], value may be substituted via key definition $_k = (is_array($keys))?$keys:array($keys); foreach ($_k as $k => $v) { $key = (is_int($k))?$v:$k; if (isset($array[$key]) && !empty($array[$key])) return ((is_int($k))?$array[$key]:$v); } return ''; } echo dgs_Aval($a, 'what')||'nope';
based on eBWrj
Output for 4.3.0 - 7.2.0
1