简体   繁体   English

PHP对日期列排序多维数组

[英]php sort multidimensional array on date column

I have an array $dataStoreForTableImport set up in the following way. 我通过以下方式设置了数组$ dataStoreForTableImport。

$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. 如果articleDate在给定日期之前,我希望能够从此数组中删除行。

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 日期格式为-2007年2月10日

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. 在SQL查询中,使用WHERE子句按日期过滤,并使用ORDER BY子句按日期排序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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