EchoFool Posted August 6, 2008 Share Posted August 6, 2008 I need some help as i do not know how to do this. I have a variable in a list like this: $Var = 'item1,item2,item3'; (theres about 50 more but you know what i mean). What i want to do it put every item into its own variable using an array. Then when the array is compiled, some how while loop it to process each item. Is there any chance you can demonstrate an example of how this is done then i can learn from that, as im good at learning from examples. Link to comment https://forums.phpfreaks.com/topic/118449-list-array-into-a-while-loop/ Share on other sites More sharing options...
adam84 Posted August 6, 2008 Share Posted August 6, 2008 $itemArray = array(); $items = explode( ',', $Var); for($i = 0; $i < count($items); $i++){ $itemArray[$i] = $items[$i]; } Link to comment https://forums.phpfreaks.com/topic/118449-list-array-into-a-while-loop/#findComment-609696 Share on other sites More sharing options...
wildteen88 Posted August 6, 2008 Share Posted August 6, 2008 Use explode - this will sepaerated each item on its own in an array, then to loop through the array use a foreach loop $Var = 'item1,item2,item3'; $items = explode(',', $Var); foreach($items as $item) { echo $item . '<br />'; } // OR as a one liner echo implode('<br />', $items); Link to comment https://forums.phpfreaks.com/topic/118449-list-array-into-a-while-loop/#findComment-609698 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.