At the top of document I declared
$final = array();
Then I got the following functions
function delivery($optional = null){
global $db;
//$return = $_POST;
if(!empty($optional['reportdate_from'])) {
//$return1['from'] = $optional['reportdate_from'];
}
if(!empty($optional['reportdate_to'])) {
//$return1['from'] = $optional['reportdate_from'];
}
$sth = $db->prepare("SELECT DATE(date) Date, COUNT(number) totalCOunt FROM numbers GROUP BY DATE(date)");
$sth->execute();
$result = $sth->fetchAll();
$return1['name'] = 'W doręczeniu';
foreach ($result as $row1) {
$date1 =strtotime($row1['Date'])*1000;
$return1['data'][] = array($date1, (int)$row1['totalCOunt']);
}
return array_push($final,$return1);
// echo json_encode($final,true);
}
function delivered($optional){
global $db;
$return = $_POST;
if(!empty($optional['reportdate_from'])) {
//$return1['from'] = $optional['reportdate_from'];
}
if(!empty($optional['reportdate_to'])) {
//$return1['to'] = $optional['reportdate_to'];
}
$sth = $db->prepare("SELECT DATE(date) Date, COUNT(number) totalCOunt FROM numbers Where `return` = 1 AND rdate != '0000-00-00 00:00:00' GROUP BY DATE(date)");
$sth->execute();
$result = $sth->fetchAll();
$return1['name'] = 'Doręczone';
foreach ($result as $row1) {
$date1 =strtotime($row1['Date'])*1000;
$return1['data'][] = array($date1, (int)$row1['totalCOunt']);
}
return array_push($final,$return1);
}
and at the very bottom of the document I have got:
echo json_encode($final,true);
The overall output is [] No Properties And Warning: array_push() expects parameter 1 to be array, null given in
All the arrays are not null it only happens if they are array_push(ed)
Calling the functions.
case "test": delivery($optional); break;
case "test1": delivered($optional); break;
Why is this error occuring?