简体   繁体   中英

php sort multidimensional array on date column

I have an array $dataStoreForTableImport set up in the following way.

$dataStoreForTableImport['title']
$dataStoreForTableImport['content']
$dataStoreForTableImport['date']
$dataStoreForTableImport['link']
$dataStoreForTableImport['username']
$dataStoreForTableImport['website']

It contains data as below

Array
(
[0] => Array
    (
        [title] => Quote from Tony Blair
        [content] => ... from beating it I'm afraid." (Tony Blair, Sky News) He had every opportunity to put religion in its ...
        [articledate] => 28/09/2013
        [link] => http://boards.fool.co.uk/message.asp?source=isesitlnk0000001&mid=12890951
        [Username] => Michael Dray
        [website] => The Motley Fool
    )

[1] => Array
    (
        [title] => Re: The Tony Blair Show
        [content] => ... I am irritated that he got such an easy ride; Why? Because he is not to your political liking? He was a witness; he was not on trial and he spoke under oath. What did you expect Jay to ask him? I had dealings with a QC a few years ago. He was as ...
        [articledate] => 28/05/2012
        [link] => http://boards.fool.co.uk/message.asp?source=isesitlnk0000001&mid=12564154
        [Username] => Michael Dray
        [website] => The Motley Fool
    )

[2] => Array
    (
        [title] => Re: The Tony Blair Show
        [content] => ... If your doubts about Jay's competence/bias were shared I'm sure it would have been debated ad nauseam on Radio 4. Eh - are you serious? I'm a Radio 4 fan - but thats despite its hatred of all things right of centre, not becuase of. ...
        [articledate] => 28/05/2012
        [link] => http://boards.fool.co.uk/message.asp?source=isesitlnk0000001&mid=12564167
        [Username] => Michael Dray
        [website] => The Motley Fool
    )

[3] => Array
    (
        [title] => Re: The Tony Blair Show
        [content] => ... Maybe Tony should have brought Cherie with him - remember Rupert Murdoch and the reaction of Wendi Deng to the custard pie incident. IMHO Cherie is every bit as intimidating:-) Wendi Deng did not eject the pie flinger, she intervened when he acted. Use of an angled bat to deflect criticism from ...
        [articledate] => 30/05/2012
        [link] => http://boards.fool.co.uk/message.asp?source=isesitlnk0000001&mid=12565346
        [Username] => Michael Dray
        [website] => The Motley Fool
    )

[4] => Array
    (
        [title] => Re: The Tony Blair Show
        [content] => ... What did surprise me was the fact that he had his own personal bodyguards in the hearing with him. Although, given the level of security that allowed that protester to break into the hearing, maybe he had a point! Eh? He is clearly at risk of terror ...
        [articledate] => 28/05/2012
        [link] => http://boards.fool.co.uk/message.asp?source=isesitlnk0000001&mid=12564500
        [Username] => Michael Dray
        [website] => The Motley Fool
    )

I want to be able to remove rows from this array that if the articleDate is before a given date.

I have tried everything but it does not seem to work. I am not even able to get it to sort correctly by date?

The date comes in the format - February 10, 2007

I have used

$sortDate = date('d/m/Y', strtotime($sortDate));

to format it to the format shown in the array above.

Can anyone please help?

Thanks

Mike

Do the filtering and sorting of rows in the database backend. This will improve the performance of you app. Use a WHERE clause for filtering by date and an ORDER BY clause for ordering by date in you SQL query.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM