嗨,大家好我有一个填充日期操纵PHP数组
Array
(
[0] => 2012-04-04
[1] => 2012-04-06
[2] => 2012-04-06
[3] => 2012-04-06
[4] => 2012-04-06
[5] => 2012-04-06
[6] => 2012-04-06
[7] => 2012-04-11
[8] => 2012-04-12
[9] => 2012-04-12
[10] => 2012-04-13
[11] => 2012-04-13
[12] => 2012-04-13
[13] => 2012-04-13
[14] => 2012-04-13
[15] => 2012-04-13
[16] => 2012-04-13
)
数组如何将我遍历数组,发现在项目之间天差旁边阵列对方。例如,我想呼应OUT [0]和[1]是 “2” 天之间
差 [1]和[2]为 “0” 天
之间差:)
管理从顶部的答案得到一些输出,但我只希望它显示,如果有日期的差异。
从这个if语句没有输出,但 - 更新 -
$count = count($datestack);
for ($i = 0; $i < $count - 1; $i++) {
$datetime1 = new DateTime($datestack[$i]);
$datetime2 = new DateTime($datestack[$i + 1]);
$interval = $datetime1->diff($datetime2);
if ($arr[$i] === $arr[$i+1]){
echo $interval->format('%R%a days');
}
}
尝试坚持与您的问题.. http://stackoverflow.com/questions/9917611/inserting-an-image-multiple-times-based-on-difference-between-2-numbers -php http://stackoverflow.com/questions/9918065/looping-json-document-loading-string-into-array-then-manipulating-the-document – 2012-03-29 02:30:36
道歉我认为这是一个稍微不同的问题,因为我正在努力与突出显示数组项目的语法 – user1064660 2012-03-29 02:32:58