i have case where there are a timestamp date contains of date format. Then i wanted to build a chart that show the number of "clicked" items "per day" ,
//array declaration
$array1 = array("Date" => 0);
$array2 = array("Date" => 0);
$array3 = array("Date" => 0);
$array4 = array("Date" => 0);
$array5 = array("Date" => 0);
$array6 = array("Date" => 0);
$array7 = array("Date" => 0);
$array8 = array("Date" => 0);
//var_dump($array);
foreach ($_sql as $result1) {
$timestamp = $result1['timestamp'];
$itemType = $result1['itemType'];
//separate the time and date
$explodeTime = explode(" ", $timestamp);
$date = $explodeTime[0];
//$arrDate = array($date);
//var_dump($Date);
//if the item type is 1;
if($itemType == 1 ){
//check the existence
if(array_key_exists($date,$array1)){
//if exist increment the click by 1
foreach ($array1 as $key => $value) {
$array1[$key]=$value + 1;
//var_dump($array1);
}
}
//else add new record and set default value as 1
else{
//echo "Insert new Key";
//$array1 = array($date => 1);
//var_dump($array1);
//var_dump($array1);
//exit();
}
}
i wanted to get my array result with this format
array(1) {
["2009-04-17"]=> 211
int(1)
}
array(1) {
["2009-04-18"]=> 1213
int(1)
}
array(1) {
["2009-04-19"]=> 1232
int(1)
}
array(1) {
["2009-04-20"]=> 32312
int(1)
}
so i can get the value of date, then it is easily to convert the data into json, then insert into the Chartjs.
sorry if my question is not clear, because i have just started learn php.