Created
May 4, 2020 18:06
-
-
Save dikiwidia/4b1d1cbb259eb24dff2be299a0512125 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$data = [ | |
[ | |
"nama" => "Moch Diki Widianto", | |
"alamat" => "Rangkasbitung, Banten", | |
"jabatan" => "CEO Baduytech Solutions" | |
], | |
[ | |
"nama" => "Asep Mularwan", | |
"alamat" => "Bandung, Jawa Barat", | |
"jabatan" => "Operational Manager" | |
], | |
[ | |
"nama" => "Innayatul Ummah", | |
"alamat" => "Banda Aceh, Aceh", | |
"jabatan" => "Accounting Manager" | |
], | |
[ | |
"nama" => "Fatimah Az-Zahra", | |
"alamat" => "Padang, Sumatera Barat", | |
"jabatan" => "IT Manager" | |
] | |
]; | |
echo "<h1>Dengan For</h1>"; | |
// Karena ada 4 data, berarti posisi arraay dari 0,1,2,3 karena dimulai dari 0 | |
// Kalau ++ tandanya increment, atau naik ditambah 1 setelah perulangan. | |
for($i=0; $i<count($data); $i++){ // loop dengan for | |
echo $data[$i]["nama"]; // $data[0]['nama']; | |
echo "<hr />"; | |
} | |
echo "<br /><br /> <h1>Dengan Foreach </h1>"; | |
foreach($data as $item){ //dibuat alias lalu dipanggil key nya | |
echo $item["nama"]; | |
echo "<hr />"; | |
} | |
echo "<br /><br /> <h1>Dengan While </h1>"; | |
$no = 0; | |
while($no < count($data)){ //harus true | |
echo $data[$no]["jabatan"]; // memanggil barisnya $data[0]["nama"]; | |
echo "<hr />"; | |
$no++; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment