数组,如何显示“更改值”只要 [英] Array, how to display the "changing values" only

查看:110
本文介绍了数组,如何显示“更改值”只要的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个日期和季节的数组,每天有一个条目。

数组看起来像这样:

pre> 2009-10-28 00:00:00(好季节)

2009-10-29 00:00:00(好季节)

2009-10-30 00:00:00(好季节)

2009-10-31 00:00:00(好季节)

2009 -11-01 00:00:00(好季节)

2009-11-02 00:00:00(不良季节)

2009-11-03 00: 00:00(不好的季节)

2009-11-04 00:00:00(不好的季节)

2009-11-05 00:00:00(不好的季节)


解决方案

循环播放,保留上个赛季的记录:

  $ lastSeason =''; 
$ b $ foreach($ array为$ date => $ season)
{
if($ season!= $ lastSeason)
echoSeason changed on。 $日期;

$ lastSeason = $ season;
}


Let's say I have an array with dates and seasons, there is one entry for each day. I would like to print the array row only when the season value is changing.

the array look like that:

2009-10-28 00:00:00 (good season)  

2009-10-29 00:00:00 (good season) 

2009-10-30 00:00:00 (good season) 

2009-10-31 00:00:00 (good season) 

2009-11-01 00:00:00 (good season) 

2009-11-02 00:00:00 (bad season) 

2009-11-03 00:00:00 (bad season) 

2009-11-04 00:00:00 (bad season) 

2009-11-05 00:00:00 (bad season) 

解决方案

Loop through, keeping a record of the last season:

$lastSeason = '';

foreach ($array as $date => $season)
{
    if ($season != $lastSeason)
        echo "Season changed on " . $date;

    $lastSeason = $season;
}

这篇关于数组,如何显示“更改值”只要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆