我制作了一个程序来查找当前日期,然后在 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 月份找不到,因为将月份与日期混淆了。有什么解决办法吗?