Jump to content

[SOLVED] Extrack Array


gtal3x

Recommended Posts

can anyone help me extracting this array using foreach...

$country_list = array(
"1" =>	array("country" => "Afghanistan", "flag" => "af.png"),
"2" =>	array("country" => "Albania", "flag" => "al.png"),
"3" =>	array("country" =>	"Algeria", "flag" => "dz.png"),
"4" =>	array("country" =>	"Andorra", "flag" => "ad.png"),

I wont it to dispay:

1 Afganistan

2 Albania

3 Algeria..... and so on

 

thanx in advance

Link to comment
https://forums.phpfreaks.com/topic/76950-solved-extrack-array/
Share on other sites

wat am i gonna read there? they dont explain anythin just give u examples, maybe if i was a big guru i would understand but am not

btw i know how to extract keys and values from array, the problem here is that i got arrays inside array and am very confused

Link to comment
https://forums.phpfreaks.com/topic/76950-solved-extrack-array/#findComment-389627
Share on other sites

You need to nest some foreach's...

 

$country_list = array(
"1" =>	array("country" => "Afghanistan", "flag" => "af.png"),
"2" =>	array("country" => "Albania", "flag" => "al.png"),
"3" =>	array("country" =>	"Algeria", "flag" => "dz.png"),
"4" =>	array("country" =>	"Andorra", "flag" => "ad.png"),

 

echo "<ol>\n";
foreach ($country_list as $index=>$array){
foreach ($array as $type=>$value){
if($type == "country"){echo "\t<li>".$value."</li>\n";}
}
}
echo "</ol>";

Link to comment
https://forums.phpfreaks.com/topic/76950-solved-extrack-array/#findComment-389631
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.