Php 添加到数组中的月份
您好,我创建了一个数组,其中我将“25/11/2015”增加1个月。我有一个关于它如何工作的问题。我目前正在使用“strottime(“+1个月,$currentdate)”。我想知道为什么在我的数组的第一行中不直接添加+1个月。取而代之的是我想要的11月15日,但我想知道为什么会发生这种情况 目前我得到: 11月15日Php 添加到数组中的月份,php,arrays,Php,Arrays,您好,我创建了一个数组,其中我将“25/11/2015”增加1个月。我有一个关于它如何工作的问题。我目前正在使用“strottime(“+1个月,$currentdate)”。我想知道为什么在我的数组的第一行中不直接添加+1个月。取而代之的是我想要的11月15日,但我想知道为什么会发生这种情况 目前我得到: 11月15日 12月15日 1月16日 为什么我不输出这个结果: 十二月十五日 1月16日 二月十六日 这是我的密码: $date = "2015-11-25"; $start = strt
12月15日
1月16日 为什么我不输出这个结果: 十二月十五日 1月16日 二月十六日 这是我的密码:
$date = "2015-11-25";
$start = strtotime($date);
$currentdate = $start;
$times_table = array();
for($i = 0; $i <= 3; $i++){
$times_table[$i] = array();
}
echo "<pre>";
for($i = 0; $i <= 3; $i++){
for($j = 0; $j <= 4; $j++){
if ($j == 0){
$times_table[$i][$j]= "Version 5" ;
}
else if ($j == 1){
$cur_date = date("M-y", $currentdate);
$currentdate = strtotime('+1 month', $currentdate);
$times_table[$i][$j]= $cur_date ;
echo $cur_date . ">". "<br />";
}
else{
$times_table[$i][$j]= "gary" ;
}
if ($j == 3) {
$numbers = mt_rand(1, 100);
$times_table[$i][$j]= $numbers ;
}
if ($j == 4){
if($i == 0 || $i == 3)
{
$pay = "P";
$times_table[$i][$j]= $pay ;
}
else{
$int = "I";
$times_table[$i][$j]= $int ;
}
}
}
}
$date=“2015-11-25”;
$start=strottime($date);
$currentdate=$start;
$times_table=array();
对于($i=0;$i你写的就是你得到的:
在添加一个月之前,您将$currentdate值设置为$cur_date,然后存储$cur_date值。这就是为什么它不会立即添加1个月的原因(它直接添加到$currentdate,但不是添加到$cur_date)您在echo中有
。如果您明白了。echo$cur_date。“>”;这里,您连接了“>”和换行符,那么为什么您希望所有的字符都在同一行中呢?很抱歉,它的输出不正确。我的问题是,我的数组从11月15日开始,但为什么不立即将1添加到12月15日的日期
$cur_date = date("M-y", $currentdate);
$currentdate = strtotime('+1 month', $currentdate);
$times_table[$i][$j]= $cur_date ;