+ 1

Why echo $people[1] gives an error ?

It shows error on output Its an associative array <?php> $people= array("david"=>"21","amy"=>"29"); Echo $people[1]; ?> Op: error

16th May 2019, 1:38 PM
Shirish Chaudhari
Shirish Chaudhari - avatar
2 Answers
+ 7
The values have their own defined keys, so they don't "answer" to numeric keys. Johann Ditrich has linked to the lesson: https://www.sololearn.com/learn/PHP/1808/
16th May 2019, 3:06 PM
Kainatic [Mostly Inactive Now]
Kainatic [Mostly Inactive Now] - avatar
+ 5
Try echo $people['amy']; because it's an associav and not a numeric array. So the keys in your example are 'david' and 'amy'. https://www.sololearn.com/learn/PHP/1808/
16th May 2019, 2:43 PM
Johann
Johann - avatar