3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function one($s, $p) { return array_intersect_key($s, array_flip($p)); } function two($s, $p) { foreach($s as $key => $value) { if(!array_key_exists($key, $p)) { unset($s[$key]); } } return $s; } function benchmark(callable $function, $args=array(), $count=1) { $time = microtime(1); for($i=0; $i<$count; $i++) { $result = call_user_func_array($function, $args): } return [ 'total_time' => microtime(1) - $time, 'average_time' => (microtime(1) - $time)/$count, 'count' => $count ]; } $searchParameters = array( 'parameter1' => 'value1', 'parameter2' => 'value2', 'parameter3' => 'value3', ); $allowedParamters = array('parameter1','parameter2'); echo('array_intersect'.PHP_EOL); var_dump(benchmark('one', [$searchParameters, $allowedParamters], 1E6)); echo('foreach'.PHP_EOL); var_dump(benchmark('two', [$searchParameters, $allowedParamters], 1E6));
Output for 5.3.0 - 5.4.24
Parse error: syntax error, unexpected ':' in /in/HRrYv on line 24
Process exited with code 255.