Jump to content

List array into a while loop


EchoFool

Recommended Posts

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

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);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.