Explode to array and print each element as list item
explode, foreach, php
Solution
$numbers = '1,2,3';
$array = explode(',', $numbers);
foreach ($array as $item) {
echo "<li>$item</li>";
}
Problem
I have a set of numbers in a table field in database, the numbers are separated by comma ','. I am trying to do the following: Step 1. : SELECT set of numbers from database and explode it to array : ``` $array = explode(',', $set_of_numbers); ``` Step 2. : Print each element of the array as list item by using `foreach loop` : ``` foreach ($array as $list_item => $set_of_numbers){ echo "<li>"; print_r(array_list_items($set_of_numbers)); echo "</li>";} ``` Please anybody tell me what is wrong. Thank you.