7/1/2023 0 Comments Foreach php optmize![]() ![]() Since i mentioned that benchmarking page on loops, it also includes the benchmark for single(') and double(") quotes. ![]() You can find this VERY interesting benchmarking on loops on PHP. The difference between these two is that the second doesn't run count operation n times while the first one did. The first way includes the operation count into the loop while the second one pre-calculate the total number of loop outside it. The above shows two different ways of writing a for loop. But how do you know which one is the best way to loop your data? Apparently, using a for loop is better than foreach and while loop if the maximum loop is pre-calculated outside the for loop! What do i mean? Basically is this. There are many ways we can define a loop in PHP. There is something more interesting about loop in PHP. ![]() And loop is considered as efficiency killer if you have many nested loop (means loop in a loop) as one loop will required to run 'n' times and if you have 1 nested loop, this means your program will have to run n 2 times. We will also look at many benchmarking of these tips where possible! LoopĮvery program will required certain amount of loop. In this article, i will try to provide you with some tips that can serve as micro optimization for your code and could also add on to the list of knowledge that you have in PHP. However, there might be some unknown information that you might not aware in PHP that can help improve your code. And we can easily increase the efficiency of our code just by putting in some effort during development. There are many ways to improve the way you write your PHP code. ![]()
0 Comments
Leave a Reply. |