I have the following array (called $available_dates) in PHP:
Array
(
[0] => 2017-11-28
[1] => 2017-11-29
[2] => 2017-11-30
)
This array is passed to a function that queries an API to get tour times associated with these dates:
for($a=0;$a<count($available_dates);$a++) {
$url = "HTTP API END POINT";
$json = json_decode(get_JSON($url),true);
$total_records = intval($json['total']);
$tour_times = array();
for($b=0;$b<$total_records;$b++) {
//$tour_time is a string e.g. 11:30 AM
$tour_time = $json['item'][$b]['time'];
//Keep track, add to my time array
$tour_times[] = $tour_time;
}
//Issue is here
$available_dates[$a][] = $tour_times;
}
This produces the following error, at the line indicated above:
[] operator not supported for strings in
What I want to create is, and please excuse my bad formatting and representation:
Array
(
[0] => 2017-11-28
array(0 => '12:00 PM', 1 => '2:00 PM')
[1] => 2017-11-29
array(0 => '11:00 PM', 1 => '10:00 PM')
[2] => 2017-11-30
array(0 => '9:00 AM', 1 => '2:00 PM')
)