- func_get_arg: documentation ( source)
<?php
function first(/* [(array $array, $key) | $value]... */)
{
$count = func_num_args();
for ($i = 0; $i < $count - 1; $i++)
{
$arg = func_get_arg($i);
if (!isset($arg))
{
continue;
}
if (is_array($arg))
{
$key = func_get_arg($i + 1);
if (is_null($key) || is_string($key) || is_int($key) || is_float($key) || is_bool($key))
{
if (isset($arg[$key]))
{
return $arg[$key];
}
$i++;
continue;
}
}
return $arg;
}
if ($i < $count)
{
return func_get_arg($i);
}
return null;
}
$test = array();
echo $test ? 'truthy' : 'empty', "\r\n";
echo first(array($test[0], 0), '$test[0][0] is not set'), "\r\n";
echo $test ? 'truthy' : 'empty', "\r\n";