Reputation: 55
A simple question for pros. There is a code with which we are getting access to an array value:
foreach($basket as $k=>$v)
echo "{$v[0]['title']} <br>";
it prints to browser:
book 1
book 2
etc...
and now, if we delete the braces such as this:
echo "$v[0]['title'] <br>";
it prints:
array['title']
array['title']
etc...
so interpreter "sees" $v[0]
and this is an array yes. but he can't get access to ['title']
.
plz tell newbie, why does it happen? i know that braces interpolate a variables in cases when there are some letters around. But there are no letters around here.
Upvotes: 1
Views: 648
Reputation: 8022
That's because echo
first considers $v[0]
as variable and then prints it's STRING value which is array and then ['title']
gets interpreted as a plain text string.
Upvotes: 2