I am working on a website with CodeIgniter, I need to create a select for each element I receive in an array or json. I do not know which is the best option as a response to a post I do with ajax. The problem I have is that I receive an array like this:
(Part of the var_dump)
array (size=5)
'Monday 10' =>
array (size=8)
0 => string '16:00:00' (length=8)
1 => string '16:30:00' (length=8)
2 => string '17:00:00' (length=8)
3 => string '17:30:00' (length=8)
4 => string '18:00:00' (length=8)
5 => string '18:30:00' (length=8)
6 => string '19:00:00' (length=8)
7 => string '19:30:00' (length=8)
'Monday 17' =>
array (size=8)
0 => string '16:00:00' (length=8)
1 => string '16:30:00' (length=8)
2 => string '17:00:00' (length=8)
3 => string '17:30:00' (length=8)
4 => string '18:00:00' (length=8)
5 => string '18:30:00' (length=8)
6 => string '19:00:00' (length=8)
7 => string '19:30:00' (length=8)
And if I receive a json through json_encode
I get something like this:
{
"Monday 10": ["16:00:00", "16:30:00", "17:00:00", "17:30:00", "18:00:00", "18:30:00", "19:00:00", "19:30:00"],
"Monday 17": ["16:00:00", "16:30:00", "17:00:00", "17:30:00", "18:00:00", "18:30:00", "19:00:00", "19:30:00"],
"Monday 24": ["16:00:00", "16:30:00", "17:00:00", "17:30:00", "18:00:00", "18:30:00", "19:00:00", "19:30:00"],
"Monday 31": ["16:00:00", "16:30:00", "17:00:00", "17:30:00", "18:00:00", "18:30:00", "19:00:00", "19:30:00"],
"Monday 07": ["16:00:00", "16:30:00", "17:00:00", "17:30:00", "18:00:00", "18:30:00", "19:00:00", "19:30:00"]
}
I do not know how to access each element; I have already tried iterating with the function $.each
but I access to: [,{,"
and so on. The idea is that I keep a label with the day, and in the select the schedules.