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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.