PHP Array Help

Soldato
Joined
28 Apr 2011
Posts
15,210
Location
Barnet, London
Hi, I've been dabbling in PHP for months now so I know I should know this, but can anyone confirm I would be doing this right if I made an array like this -

Code:
$item = array(
"date" => $date,
"name" => $name,
"comment" => $comment
);

Then added it to an array like this -

Code:
array_push($items, $item);

Would I then access the comments for example, like this -

Code:
$thisComment = $items[$x]['comment'];

And how would I sort the items by 'date', given the date format goes yyyy-mm-dd, so should work as a straight forward sort?

Thanks!
 
Yep, a sort should do it. As the explanation in SO says, you need to convert the dates to numerical timestamps if you want to sort by actual date. Although having the date in yyyy-mm-dd should result in the same thing.
 
Back
Top Bottom