我有一个返回数据库结果的函数,如下所示:
<?php print_r($homepagematches; ?>
Array
(
[0] => Array
(
[matchid] => 30
[matchtitle] => Testing This!
[matchaverage] => 1
[matchyoutubecode] => New Match
[casterid] => 1
[matchtype] =>
[matchdate] => 2013-05-24 02:19:49
[matchcasteryoutube] => http://youtube.com/huskystarcraft
[matchcaster] => HuskyStarcraft
)
[1] => Array
(
[matchid] => 27
[matchtitle] => Psy vs Camara
[matchaverage] => 1
[matchyoutubecode] => nefC9vkMfG8
[casterid] => 1
[matchtype] =>
[matchdate] => 2013-05-24 02:13:10
[matchcasteryoutube] => http://youtube.com/huskystarcraft
[matchcaster] => HuskyStarcraft
)
该函数返回过去 3 天内的所有匹配项,我想弄清楚的是如何重组数组,以便我可以在发布日期的情况下显示匹配项。我知道这可能需要一个 foreach 循环,我只是无法理解我需要实现的概念。
$matchdate = '';
foreach($this->data['homepagematches'] as $match){
if($matchdate != date('m/d', strtotime($match['matchdate'])) || $matchdate == ''){
$homematch[date('m/d', strtotime($match['matchdate']))] = array(
"matchtitle" => $match['matchtitle']);
}
基本上我需要数组看起来像:
Array
(
[05/24] => Array
(
[matchid] =>30
[matchtitle] => Testing This!
[matchyoutubecode] => New Match
[casterid] = 1
)
)