I am trying to create table in PHP using array but I am getting parse error in my foreach line. Don't know why its giving me syntax error.
$message = '<table border=1>
<tr>
<th><b>Order Details</b></th>
</tr>
'.foreach ($json_array->request->list as $value) {
$wineId = $value->wineId;
$wineName = $value->wineName;
$noOfDrinks = $value->noOfDrinks;
.'
<tr>
<td>ID</td><td>'.$wineId.'</td>
</tr>
<tr>
<td>Name</td><td>'.$wineName.'</td>
</tr>
<tr>
<td>Quantity</td><td>'.$noOfDrinks.'</td>
</tr>
'. } .'
</table>';
Try this, use string concatenation except php code
$message = '<table border=1>
<tr>
<th><b>Order Details</b></th>
</tr>';
foreach ($json_array->request->list as $value) {
$wineId = $value->wineId;
$wineName = $value->wineName;
$noOfDrinks = $value->noOfDrinks;
$message .= '<tr>
<td>ID</td><td>'.$wineId.'</td>
</tr>
<tr>
<td>Name</td><td>'.$wineName.'</td>
</tr>
<tr>
<td>Quantity</td><td>'.$noOfDrinks.'</td>
</tr>';
}
$message .='</table>';