how to display array data in table formate in php using foreach
Get the solution ↓↓↓Solution:
One way to rome...
$collector=array();
//flatten your array struct, take datetime from first level and id from second
foreach($array as $date => $set){
foreach($set as $aff_id => $subset){
//bind datetime
$subset['DATE'] = $date;
//bind id
$subset['AFF_ID'] = $aff_id;
//sort by key to generate an valid table later
ksort($subset);
//collect it
$collector[]=$subset;
}
}
//create header
$table = "<table><tr><th>".implode('</th><th>',array_keys($collector[0]))."</th></tr>";
//create rows
foreach($collector as $set){
$table .= "<tr><td>".implode('</td><td>',$set)."</td></tr>";
}
$table .= "</table>";
//output
print $table;
Change the code if needed.
Answer
Solution:
use 2 for each
<?php foreach ($array1 as $arrray =>$value){
foreach ($value as $abc => $value2){ ?>
<tr>
<td> <?php echo $value2['click']; ?></td>
<td> all otheres</td>
</tr>
<?php }
} ?>
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: regex stop at first match
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.