RynMan Posted March 31, 2010 Share Posted March 31, 2010 Hi guys I have some code performing a loop. What I'd like, is for some of the particular values I get during my loop, to be stored in an array so I can access them later on the page. How can I basically say 'on each loop, add this value to an array' ? Many thanks! Link to comment https://forums.phpfreaks.com/topic/197098-assigning-values-during-a-loop/ Share on other sites More sharing options...
trq Posted March 31, 2010 Share Posted March 31, 2010 $arr = array(); foreach ($a as $b) { $arr[] = $b; } Link to comment https://forums.phpfreaks.com/topic/197098-assigning-values-during-a-loop/#findComment-1034598 Share on other sites More sharing options...
RynMan Posted March 31, 2010 Author Share Posted March 31, 2010 $arr = array(); foreach ($a as $b) { $arr[] = $b; } Thanks! Then how would I basically get it to echo the contents until it was empty? i.e. if there were 5 items in the array....have it do.... echo $Item[0]; echo $Item[1]; echo $Item[2]; echo $Item[3]; echo $Item[4]; without having to have the code for each array? For example if my array size is always changing, I just want to echo what is there.... Link to comment https://forums.phpfreaks.com/topic/197098-assigning-values-during-a-loop/#findComment-1034609 Share on other sites More sharing options...
trq Posted March 31, 2010 Share Posted March 31, 2010 You would use another loop. foreach ($item as $val) { echo $val; } Link to comment https://forums.phpfreaks.com/topic/197098-assigning-values-during-a-loop/#findComment-1034612 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.