Test In_array, Isset, array_key_exists performance. Self-written simple test code:
Ini_set(' Display_errors ',true);error_reporting(E_all);d Ate_default_timezone_set (' PRC ');functionTtt$a,$b){ $u 1=$b[0]-$a[0]; $u 2=$b[1]-$a[1]; Echo Number_format($u 1, 8). ' Seconds '.$u 2.‘ bytes; Echo' <br/> ';}$t 0= [ Microtime(true),memory_get_usage ()];$arr 1= [];$arr 2= []; for($i= 0;$i< 1000;$i++ ){ $arr 1[] = ' a '.$i; $arr 2[' A '.$i] =true;}$k= ' a862 ';$t 1= [ Microtime(true),memory_get_usage ()]; for($i= 0;$i< 100;$i++ ){ In_array($k,$arr 1);}$t 2= [ Microtime(true),memory_get_usage ()]; for($i= 0;$i< 100;$i++ ){ isset($arr 2[$k]);}$t 3= [ Microtime(true),memory_get_usage ()]; for($i= 0;$i< 100;$i++ ){ array_key_exists($k,$arr 2);}$t 4= [ Microtime(true),memory_get_usage ()];ttt ($t 1,$t 2); TTT ($t 2,$t 3); TTT ($t 3,$t 4);
Results from my Computer output:
0.01480007 sec 328 bytes
0.00003886 sec 328 bytes
0.00008416 sec 328 bytes
Rough it's best to use Isset, In_array consumes more time than array_key_exists.
If in the case of data volume comparison, the situation of these three is basically close, but still isset is the fastest.
Therefore, in the design of nilcms to consider this aspect of the problem. Remember.
Test In_array, Isset, array_key_exists performance in PHP