there are various common tasks in PHP which can be done in several ways.
this site aims to benchmark these different approaches to find the fastest solution to the problem.
sometimes there are builtin PHP functions which are (in the most cases) the fastest solutions.
but their options are limited so there might be some benchmarks which don't make sense to you at first.
time required (shorter is better)
rank / method / description / code
resulting output
<?php
// ------- check if a string is in the values of an array with in array
// -- the setup
$workdata = range('a','z');
$item2find = 'u';
// -- the code to test
$newworkdata = 'string '.(in_array($item2find,$workdata) ? '' : 'not').' found';
?>
string foundback to the PHP benchmark results
<?php
// ------- check if a string is in the values of an array with join / strpos
// -- the setup
$workdata = range('a','z');
$item2find = 'u';
// -- the code to test
if(strpos(join(' ',$workdata),$item2find) !== false )
{
$newworkdata = 'string found';
}else{
$newworkdata = 'string not found';
}
?>
string foundback to the PHP benchmark results
<?php
// ------- check if a string is in the values of an array with for loop / strpos
// -- the setup
$workdata = range('a','z');
$item2find = 'u';
// -- the code to test
$n = count($workdata);
for($i = 0; $i < $n; $i++)
{
if(strpos($workdata[$i],$item2find) !== false)
{
$newworkdata = 'string found';
$i = $n;
}else{
$newworkdata = 'string not found';
}
}
?>
string foundback to the PHP benchmark results