php - Can foreach architecture be modified? -


this strange question, it's interesting thought i'd ask. let's don't how php's foreach loop operates , use in format, did added counter outside , used inside foreach loop tell if we're in last element.

$counter = 1; $array_size = count($array); foreach($array $item){    //code    if($counter == $array_size){        $islast = true     } else {       $islast = false;     }    $counter++;  } 

my question is: can override or fork or inherit (or whatever want call that) original php foreach loop include new ability, can this, without need initializing counter , such.

newforeach($array $item){    //code    $islast = //something returns true/false; } 

it's interesting idea, wonder if 1 of hardcore php guys here can somehow make possible? or sort of modification way complicated without hacking language itself?!

if question "can override implementation of php's language constructs" answer no. feature of other dynamic langauges javascript or ruby referred monkey patching or duck punching.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -