[Rumor Terminator] PHPfor/foreach/while has better performance than my female friend and tells me, well, what? I 'd like to hear others say that the best foreach in php should not use for, because the performance will be better. my first reaction was that it was impossible. The second reaction was to think about why others had such a conclusion. I guess some [Rumor Terminator] PHP for/foreach/while performance comparison
My female friend told me, oh, what? I 'd like to hear other people say that the best foreach in php should not use for, because the performance will be better.
My first reaction was that it was impossible. The second reaction was to think about why others had such a conclusion.
I guess some children's paper testing for probably uses the following form:
For ($ I = 0; $ I
Child paper, each cycle needs to count the number of items in $ array, which consumes resources, unless PHP of a certain version will optimize this method in the future:
$arraySize = count($array);for($i=0; $i<$arraySize; $i++){...}
PHP's internal optimization of foreach is also like this.
Then I went online and found out how the experiment of the child paper that holds the idea of "foreach is more efficient than for". I found one of the results:
Http://www.phpq.net/research/foreach-while-for.html
As I thought, TA used the following form to test:
for($i = 0; $i < count($arr); $i++){$str .= $arr[$i];}
I changed the experiment case of TA:
$ Size = count ($ arr );
For ($ I = 0; $ I <$ size; $ I ++ ){
$ Str. = $ arr [$ I];
Efficiency comes up.