php - Count json objects in array -
struggling count of objects in array spit out number in json. can help?
try { $conn->setattribute(pdo::attr_errmode, pdo::errmode_exception); $stmt = $conn->prepare('select * date_blocks user_id = :user_id'); $stmt->execute(array('user_id' => $user_id)); while($row = $stmt->fetch()) { $starttime = strtotime($row['start_date']); $endtime = strtotime($row['end_date']); ($i = $starttime; $i <= $endtime; $i = $i + 86400) { $getdate = date('y-m-d h:i:s', $i); $return[]=array('date'=>$getdate, 'id'=>$row['id']); } } } catch(pdoexception $e) { echo 'error: ' . $e->getmessage(); } header('content-type: application/json'); echo json_encode($return);
getting number of elements in json format @ end of script:
header('content-type: application/json'); echo json_encode(count($return));
Comments
Post a Comment