Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $data=array(
- array("Volvo",22,18),
- array("BMW",15,13),
- array("Saab",5,2),
- array("Land Rover",17,15)
- );
- function parseCol($col){
- return "<td>$col</td>";
- }
- function parseRow($row){
- $row=join("",array_map("parsecol",$row));
- return "<tr>$row</tr>";
- }
- $table=join("",array_map("parseRow",$data));
- ?>
- <body>
- <table border="2" width='200'>
- <tr>
- <th>Name</th>
- <th>Stock</th>
- <th>Sold</th>
- </tr>
- <?php
- for ($a=0; $a<count($data); $a++) {
- echo "<tr>";
- for ($b=0; $b<count($data[$a]); $b++) {
- echo "<td>".$data[$a][$b]."</td>";
- }
- echo "</tr>";
- }
- ?>
- </table>
- <table border="2" width='200'>
- <tr>
- <th>Name</th>
- <th>Stock</th>
- <th>Sold</th>
- </tr>
- <?php
- foreach($data as $row){
- echo "<tr>";
- foreach($row as $col){
- echo "<td>$col</td>";
- }
- echo "<tr>";
- }
- ?>
- </table>
- <table border="2" width='200'>
- <tr>
- <th>Name</th>
- <th>Stock</th>
- <th>Sold</th>
- </tr>
- <?php echo $table; ?>
- </table>
- </body>
Add Comment
Please, Sign In to add comment