Reputation: 389
When I do var_dump($punkty); I got something like this:
array(1)
{
[0]=> array(4)
{
["id"]=> string(2) "28"
["mapa"]=> string(97) "a:3s:3:"lat";s:17:"49.21103723075132";s:3:"lng";s:18:"22.330280542373657";s:4:"zoom";s:2:"17";}"
["miasto"]=> string(5) "Cisna"
["nazwa_obiektu"]=> string(44) "Cisna - noclegi u Mirosławy w Bieszczadach"
}
}
When i do:
foreach ($punkty['mapa'] as $item)
{
echo $item;
}
I get
Invalid argument supplied for foreach()
How to solve it?
Upvotes: 2
Views: 4186
Reputation: 3075
$punkty['mapa'] is not an array in your case but the string you can only pass arrays or objects who implements the iterator to foreach loop.
Upvotes: 0
Reputation: 3308
But don't forget to verify your $punkty is not empty, for don't have an other error :-) , for sample:
if (isset($punkty )){
foreach($punkty as $item){
echo $item[0]['mapa'];
}
}
Upvotes: 0
Reputation: 324830
I think you're trying to do this:
foreach($punkty as $item) {
echo $item['mapa'];
}
Upvotes: 5