Stuck accessing array with integer primary key in PHP
Stuck accessing array with integer primary key in PHP
alexharrisdcj
Posts: 2Questions: 1Answers: 0
So, I've reached a sticking point in my little project. I'm trying to access the array properties, however I can't seem to access the array that contains the data that I need. Here's what the array looks like that I'm trying to get into...
Array
(
[action] => remove
[data] => Array
(
[110] => Array
(
[comp] => 4
[dept] => 301
[emp] => 658
[name] => "..."
[date] => 02/27/17
[clockin] => 1:54AM
[clockout] => 08:30PM
[hours] => 8.6
[changedtime] => 2017-03-01 13:16:55
[changedaction] => NULL
[DT_RowId] => 110
)
)
)
I can access "$_POST['data'] fine, however I can't do "$_POST['data'][0]" to get into the actual array by index.
I feel like this is a stupid question and I'm missing something simple.
Any help/advice would be greatly appreciated.
This discussion has been closed.
Answers
It looks like I can get into it by using a foreach loop. Is this the typical procedure?
Yes - exactly like that. It could effectively be seen as a spare array, but really its just an object key / value set, so
foreach
is exactly the right way to do it.Allan