ADHEAVEN - Natali Ardianto Official

COO tiket.com. Advisor bouncity.com. Advisor golfnesia.com. Co-founded urbanesia.com. Initiator #StartupLokal

January 3, 2012 12:33 pm

Foreach Loop Optimization

This is crazy! I’ve just found out that:

$pages = $query->result_array();
foreach ($pages as $page): 

is a lot faster than:

foreach ($query->result_array() as $page):

Crazy! It happens that $query->result_array() is called multiple times if you put it inside the foreach(). I need to learn more…

  1. agusismail reblogged this from adheaven
  2. adheaven posted this