modify array in loop
Posted
by SpawnCxy
on Stack Overflow
See other posts from Stack Overflow
or by SpawnCxy
Published on 2010-03-17T16:03:49Z
Indexed on
2010/03/17
16:11 UTC
Read the original article
Hit count: 210
php
Here is the code:
$arraya = array('a','b','c');
foreach($arraya as $key=>$value)
{
if($value == 'b')
{
$arraya[] = 'd';
//print_r($arraya); //$arraya now becomes array('a','b','c','d')
}
echo $key.' is '.$value."\n";
}
and it will get:
0 is a
1 is b
2 is c
And I wonder why 3 is d
doesn't show up??
© Stack Overflow or respective owner