I have 3 arrays
$array1 = [a,b,c,d];
$array2 = [word,word1,word2,word3];
$array3 = [3,4,6,7];
and
count($array1) == count($array2) == count($array3);
I want to print them in to a table of 3 columns.
Can someone tell me how to deal with this?
Check if it can help you :
<?php
$array1 = ['a', 'b', 'c', 'd'];
$array2 = ['word', 'word1', 'word2', 'word3'];
$array3 = [3,4,6,7];
?>
<table border="1">
<?php
foreach($array1 as $key => $val) {
echo '<tr>';
echo '<td>' . $val . '</td>';
echo '<td>' . $array2[$key] . '</td>';
echo '<td>' . $array3[$key] . '</td>';
echo '</tr>';
}
?>
</table>
A better solution would be to look at defining these as a multi-dimensional array
$array = [['a','word',3],['b','word1',4],['c','word2',6],['d','word3',7]];
echo '<table>';
foreach($array as $row)
{
echo '<tr><td>' . $row[0] . '</td><td>' . $row[1] . '</td><td>' . $row[2] . '</td></tr>';
}
echo '</table>';
something like that
$array1 = [a,b,c,d];
$array2 = [word,word1,word2,word3];
$array3 = [3,4,6,7];
$tableStr = "<table>";
foreach ($array1 as $key => $array1Value) {
$tableStr .= "<tr><td>".$array1Value.'</td><td>'.$array2[$key].'<td></td>'.$array3[$key].'</td></tr>';
}
$tableStr .= "</table>";
echo $tableStr;