sorry i got a stupid question i know but i'm in trouble, i'm unable to print the Countries from this array:
$array = json_decode('[
{
"Afghanistan": {
"lang": "en",
"browser_code": []
}
},
{
"Albania": {
"lang": "en",
"browser_code": []
}
},
{
"Algeria": {
"lang": "en",
"browser_code": []
}
}
]');
my try:
foreach($array as $key){
foreach($key as $k){
echo $k;
}
}
i tryed in many ways using a foreach(){}
loop but i'm in trouble with the logic, i just have to print out:
Afghanistan, Algeria, Algeria
Any clue?
$arrJson = json_decode('[
{
"Afghanistan": {
"lang": "en",
"browser_code": []
}
},
{
"Albania": {
"lang": "en",
"browser_code": []
}
},
{
"Algeria": {
"lang": "en",
"browser_code": []
}
}
]');
foreach($arrJson as $key=>$val){
foreach($val as $k=>$v){
echo $k." , ";
}
}
Try this:
foreach($array as $item) {
foreach ($item as $countryName => $countryData) {
echo $countryName; // Should be "Afghanistan"
echo $countryData; // Should be array('lang' => 'en', 'browser_code' => array())
}
}