Contoh Array Dua Dimensi Php dengan Data Static dan Dinamic

sudah lama ng ngepos lagi disini, dan kali ini ada kesempatan buat ngepos mskipun sedikit waktunya.

kali ini saya ngebahas array dua dimensi yang static dan dinamic

> static


<?php
$fruits = array ( "fruits" => array ( 1 => "orange",
2 => "banana",
3 => "apple"
),
"numbers" => array ( 1 => "orange",
2 => "banana",
3 => "apple"
),
"holes" => array ( 1 => "orange",
2 => "banana",
3 => "apple" )
);

echo"<ul>";
foreach($fruits as $index => $buah){
echo "<li>".$index."<ul>" ;
for($i=1;$i<=count($buah);$i++){
echo "<li>".$buah[$i]."</li>";
}
echo"</ul></li>";
}
echo"</ul>";
?>

///////////////////////////////////////////////////////////////////////////////////////////////////////////

> dinamic

teset


<?php
mysql_connect("localhost","root","12345");
mysql_select_db("belajar");
echo"<ul>";
$sql= mysql_query("SELECT DISTINCT parent_id, GROUP_CONCAT( DISTINCT child_id
ORDER BY child_id ) AS child_id_list
FROM table_anda
GROUP BY parent_id");

while($data=mysql_fetch_array($sql)){

echo "<li>".$data['parent_id']."<ul>" ;
for($i=1;$i<=count($data['child_id_list']);$i++){
echo "<li>".$data['parent_id'][$i].$data['child_id_list']."</li>";
}
echo"</ul></li>";
}
echo"</ul>";
?>

Hasilnya :

teset

jangan salah lo , diluar sana byk prgrammer yang masih lemah dalam array lo, hehehe

Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: