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

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -