Warning: Division by zero in /var/customers/webs/stc/benchmark/index.php on line 256 Test: in_array vs. key

PHP Benchmarks

Performance comparison of PHP code alternatives.

Test: in_array() vs. key

Is it faster to use a key to lookup (in arrays with many values), or in_array?

Run Again Test Menu

Result

Unfortunately, no history for this test is available.

Code

The first test, "in_array()", was:

for ($i = 0; $i < 10; $i++)
	$GLOBALS['dummy2'] = in_array($i * 20, $GLOBALS['dummy']);

The second test, "key", was:

for ($i = 0; $i < 10; $i++)
	$GLOBALS['dummy2'] = isset($GLOBALS['dummy'][$i * 20]);

Running: Linux (x86_64:1 GB) PHP (7.2.22-1+ubuntu16.04.1+deb.sury.org+1)