dynamically changing array in foreach

后端 未结 3 1634
你的背包
你的背包 2021-01-27 04:19

is it possible somehow change array which is processed by foreach? I tried this script

$iterator = 10;
$cat = array(1 => \'a\',2 => \'b\',3 => \'c\');

         


        
3条回答
  •  盖世英雄少女心
    2021-01-27 04:33

     'a',2 => 'b',3 => 'c');
    
    foreach ($cat as $k => &$c)//observe the '&'
    {
        if ($iterator < 15)
        {
            $cat[$iterator] = $iterator;
            $iterator++;
        }
        echo $c;
    } 
    ?>
    

提交回复
热议问题