0
我做了一個程序,找到當前的日期,然後在php數組中進行搜索,並顯示在今天這樣的一天發生了什麼。唯一的問題是程序無法正確讀取月份10-12。這裏是我的代碼:像今天一樣程序
的PHP數組:
$anniversary = array(
'1/01' => array (
'1813' => 'something here',
'1824' => 'something here',
'2001' => 'something here'
),
'31/12' => array(
'-450' => 'something here',
'-168' => 'something here',
'1942' => 'something here'
)
);
而且程序:
<?php
include 'array.php';
$today = date('d/m');
foreach ($anniversary[$today] as $hdate => $event) {
$table[0][] = $hdate;
$table[0][] = $event;
$counter++;
}
do {
$random = rand(0, $counter * 3);
} while($random % 2 == 0);
echo '<h2>'.$table[0][$random-1].": ".'</h2>'.
'<p>'.$table[0][$random].'</p>';
?>
的問題是,數月01-09找出並正確顯示和10個月-12找不到因爲月份與當天混淆。 任何解決方案?
'D'是 「與領先的零天」 - 爲什麼你使用''1/01''而不是''01/01''? – Griwes
另外,爲什麼不使用另一個數組級來分隔月份和日期呢?那麼'$週年[月] [日] [年]'或者什麼? – poke
修復您的縮進。 –