3v4l.org

run code in 300+ PHP versions simultaneously
<?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";
Output for git.master, git.master_jit, rfc.property-hooks
empty Warning: Undefined array key 0 in /in/TliEB on line 46 empty

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
56.16 ms | 401 KiB | 8 Q