This might be quite a trivial question, but which of these methods is best practice for structuring an array for return db results? say a list of blog posts... Sorting and group
The second is better AND simpler to set up:
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
$posts[] = $row;
}
// total number of posts
$nrPosts = count($post);
This will auto-index the array numerically, and you don't need to copy anything from $row into $post, it'll simply copy the whole row.
The second structure is better: