3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $a = array('hi' => true, 'there' => 'world', 'world' => false); 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 ''; } function __($txt) { return $txt; } function dgs_Acheck($array, $keys) { // check validity of all key's in array $out = true; $_k = (is_array($keys))?$keys:array($keys); foreach ($_k as $k) if (!($out = (isset($array[$k]) && !empty($array[$k])))) break; return $out; } echo dgs_Aval($a, 'world');
based on 5Q5lm
Output for 4.3.0 - 7.2.0