How to remove leading zeros from array keys How to remove leading zeros from array keys codeigniter codeigniter

How to remove leading zeros from array keys


You can do this (note the cast to int):

foreach ($query->result() as $row) {    $cal_data[(int)substr($row->date,8,2)] = $row->data;}


I'm guessing since you have substr(..., 8, 2) I assume it's a full date like 2017-07-30 or something like it.
So that means you can use date() to manipulate the data.

$cal_data[date("j", $row->date)] = $row->data;

Date("j") is day number without leading zeros.
http://php.net/manual/en/function.date.php