且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

分解并打印每个元素作为列表项

更新时间:2023-12-05 17:41:40

  $ numbers ='1,2,3'; 

$ array = explode(',',$ numbers);
$ b foreach($ array as $ item){
echo< li> $ item< / li>;
}


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.

$numbers = '1,2,3';

$array =  explode(',', $numbers);

foreach ($array as $item) {
    echo "<li>$item</li>";
}