l0ve2hat3 Posted November 25, 2009 Share Posted November 25, 2009 <?php $test[]=1; $test[]=2; $test[]=3; $test[]=4; $test[]=5; foreach($test as $num){ if($num==2)$test[]=6; echo $num."<br>"; } ?> How can I add to an array while in the foreach?? Link to comment https://forums.phpfreaks.com/topic/182922-seemingly-simple-array-help/ Share on other sites More sharing options...
mrMarcus Posted November 25, 2009 Share Posted November 25, 2009 exactly how you have it there will add 6 to your existing array. did you even try it? Link to comment https://forums.phpfreaks.com/topic/182922-seemingly-simple-array-help/#findComment-965470 Share on other sites More sharing options...
l0ve2hat3 Posted November 25, 2009 Author Share Posted November 25, 2009 @mrMarcus but i want it to echo in the foreach... yes i tried it. Link to comment https://forums.phpfreaks.com/topic/182922-seemingly-simple-array-help/#findComment-965477 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.