sandesh phuyal sandesh phuyal - 1 month ago 8
HTML Question

Echo colon array in table format

I am not able to convert this array which is defined by colon to display in table (as mentioned below). Can anyone please guide me.

$info='Title:Beckham,Age:43,Address:UK';


Must look like this table format:

enter image description here

Answer
<?php
$info='Title:Beckham,Age:43,Address:UK'; 
$info_array = explode(",",$info); 
$table = "<table>";

foreach($info_array as $row){
    $row_obj_array = explode(":",$row);
    $table .= "<tr><td>$row_obj_array[0]</td><td>$row_obj_array[1]</td></tr>";
}

$table.="</table>";
echo $table;
?>
Comments