I need array keys in json array to be integers. Now they are strings. Could you tell me where is my mistake?
$i = 0;
while($i < 7) {
isset($ips[date('d', $week_start + $i * 86400)])
? $ips[(int)date('d', $week_start + $i * 86400)] = count(date('d', $week_start + $i * 86400))
: $ips[(int)date('d', $week_start + $i * 86400)] = 0;
isset($time[date('d', $week_start + $i * 86400)])
? $time[(int)date('d', $week_start + $i * 86400)] = count(date('d', $week_start + $i * 86400))
: $time[(int)date('d', $week_start + $i * 86400)] = 0;
$i++;
}
return json_encode(array('unique' => $time, 'impressions' => $ips));
What you want is not possible with
json_encodeorjsonformatLook at this 2 arrays
Run
Output
You can see in
PHPthe are bothArrayNow run
Output
Conclusion
If you are setting array keys and those keys does not start with
0and increase serially it would be encoded asjsonobjectIf you want just arrays
Output