multidimensional array ke tabel

Sebagai contoh data yang akan kita ubah ke tabel HTML

// data array mahasiswa
$array = array("Dinda Dini","David Menake","Diah Dimitry");

Untuk mengubahnya ke tabel gunakan script

<?php
// arraytotable.php
$array = array("Dinda Dini","David Menake","Diah Dimitry");
echo "<table border='1'";
echo "<tr><th>Nama Mahasiswa</th></tr>";
foreach ($array as $data) {
 
	echo "<tr><td>". $data ."</td></tr>";
}
echo "</table>";
?>

bisa di akses di browser tampilannya
data array

Multidimensional Array

contoh data

// data array mahasiswa
$array = [
array("Dinda Dini","3", "[email protected]"),
array("David Menake", "3,3", "[email protected]"),
array("Diah Dimitry", "3,9", "[email protected]")
];

script untuk mengubah ke tabel HTML

<?php
// arraytotable.php
$array = [
array("Dinda Dini","3", "[email protected]"),
array("David Menake", "3,3", "[email protected]"),
array("Diah Dimitry", "3,9", "[email protected]")
];
 
echo "<table border='1'";
echo "<tr><th>Nama Mahasiswa</th><th>IPK</th><th>Email</th></tr>";
foreach ($array as $rows => $row)
{
	echo "<tr>";
	foreach ($row as $col => $cell)
	{
		echo "<td>" . $cell . "</td>";
	}	
 
}	
  echo "</tr></table>";
?>

bila di tampilkan di browser
multidimensional array ke tabel

Leave a comment

Your email address will not be published. Required fields are marked *