Accessing an element in a multidimensional array, php
I am currently developing a website in php. At the moment I am fetching all data from a table in my database and returning it as an array with a name '$divingTrips'
. It is returned in the following format using a function print_r(array_values($divingTrips))
:
Array ( [0] => stdClass Object (
[DivingTripID] => 1
[DivingTripName] => Newcastle Dive
[DivingTripLocation] => Newcastle
[DivingTripDay] => Monday
[DivingTripTime] => 12:06:57 )
[1] => stdClass Object (
[DivingTripID] => 2
[DivingTripName] => Portrush Dive
[DivingTripLocation] => Portrush
[DivingTripDay] => Thursday
[DivingTripTime] => 12:06:57 ) )
I am now trying to access individual items in an array to populate the dropdown for other purposes as well. I am trying to access an array:
echo $divingTrips[0]['DivingTripID'];
I would have expected this to repeat the value "1", however that doesn't work. Can someone please tell me what I am doing wrong? Many thanks.
+3
source to share