У меня есть следующий массив с day и totalprice:
Array (
[0] => Array ( [day] => 01/08/2019 [totalprice] => 585.00 )
[1] => Array ( [day] => 02/08/2019 [totalprice] => 585.00 )
[2] => Array ( [day] => 03/08/2019 [totalprice] => 585.00 )
[3] => Array ( [day] => 04/08/2019 [totalprice] => 585.00 )
[4] => Array ( [day] => 05/08/2019 [totalprice] => 585.00 )
[5] => Array ( [day] => 06/08/2019 [totalprice] => 585.00 )
[6] => Array ( [day] => 07/08/2019 [totalprice] => 585.00 )
[7] => Array ( [day] => 08/08/2019 [totalprice] => 585.00 )
[8] => Array ( [day] => 09/08/2019 [totalprice] => 585.00 )
[9] => Array ( [day] => 10/08/2019 [totalprice] => 585.00 )
[10] => Array ( [day] => 11/08/2019 [totalprice] => 585.00 )
[11] => Array ( [day] => 12/08/2019 [totalprice] => 585.00 )
[12] => Array ( [day] => 13/08/2019 [totalprice] => 585.00 )
[13] => Array ( [day] => 14/08/2019 [totalprice] => 585.00 )
[14] => Array ( [day] => 15/08/2019 [totalprice] => 585.00 )
[15] => Array ( [day] => 16/08/2019 [totalprice] => 585.00 )
[16] => Array ( [day] => 17/08/2019 [totalprice] => 585.00 )
[17] => Array ( [day] => 18/08/2019 [totalprice] => 585.00 )
[18] => Array ( [day] => 19/08/2019 [totalprice] => 585.00 )
[19] => Array ( [day] => 20/08/2019 [totalprice] => 585.00 )
[20] => Array ( [day] => 21/08/2019 [totalprice] => 585.00 )
[21] => Array ( [day] => 22/08/2019 [totalprice] => 585.00 )
[22] => Array ( [day] => 23/08/2019 [totalprice] => 585.00 )
[23] => Array ( [day] => 24/08/2019 [totalprice] => 585.00 )
[24] => Array ( [day] => 25/08/2019 [totalprice] => 585.00 )
[25] => Array ( [day] => 26/08/2019 [totalprice] => 585.00 )
[26] => Array ( [day] => 27/08/2019 [totalprice] => 585.00 )
[27] => Array ( [day] => 28/08/2019 [totalprice] => 585.00 )
[28] => Array ( [day] => 29/08/2019 [totalprice] => 585.00 )
[29] => Array ( [day] => 30/08/2019 [totalprice] => 585.00 )
[30] => Array ( [day] => 31/08/2019 [totalprice] => 585.00 )
[31] => Array ( [day] => 01/09/2019 [totalprice] => 410.00 )
[32] => Array ( [day] => 02/09/2019 [totalprice] => 410.00 )
[33] => Array ( [day] => 03/09/2019 [totalprice] => 0.00 )
[34] => Array ( [day] => 04/09/2019 [totalprice] => 0.00 )
[35] => Array ( [day] => 05/09/2019 [totalprice] => 0.00 )
[36] => Array ( [day] => 06/09/2019 [totalprice] => 0.00 )
[37] => Array ( [day] => 07/09/2019 [totalprice] => 0.00 )
[38] => Array ( [day] => 08/09/2019 [totalprice] => 0.00 )
[39] => Array ( [day] => 09/09/2019 [totalprice] => 0.00 )
[40] => Array ( [day] => 10/09/2019 [totalprice] => 0.00 )
[41] => Array ( [day] => 11/09/2019 [totalprice] => 0.00 )
[42] => Array ( [day] => 12/09/2019 [totalprice] => 0.00 )
[43] => Array ( [day] => 13/09/2019 [totalprice] => 0.00 )
[44] => Array ( [day] => 14/09/2019 [totalprice] => 0.00 )
[45] => Array ( [day] => 15/09/2019 [totalprice] => 0.00 )
[46] => Array ( [day] => 16/09/2019 [totalprice] => 0.00 )
[47] => Array ( [day] => 17/09/2019 [totalprice] => 410.00 )
[48] => Array ( [day] => 18/09/2019 [totalprice] => 410.00 )
[49] => Array ( [day] => 19/09/2019 [totalprice] => 410.00 )
[50] => Array ( [day] => 20/09/2019 [totalprice] => 410.00 )
[51] => Array ( [day] => 21/09/2019 [totalprice] => 410.00 )
[52] => Array ( [day] => 22/09/2019 [totalprice] => 410.00 )
[53] => Array ( [day] => 23/09/2019 [totalprice] => 410.00 )
[54] => Array ( [day] => 24/09/2019 [totalprice] => 410.00 )
[55] => Array ( [day] => 25/09/2019 [totalprice] => 410.00 )
[56] => Array ( [day] => 26/09/2019 [totalprice] => 410.00 )
[57] => Array ( [day] => 27/09/2019 [totalprice] => 410.00 )
[58] => Array ( [day] => 28/09/2019 [totalprice] => 410.00 )
[59] => Array ( [day] => 29/09/2019 [totalprice] => 410.00 )
[60] => Array ( [day] => 30/09/2019 [totalprice] => 410.00 )
[61] => Array ( [day] => 01/10/2019 [totalprice] => 235.00 )
[62] => Array ( [day] => 02/10/2019 [totalprice] => 235.00 )
[63] => Array ( [day] => 03/10/2019 [totalprice] => 235.00 )
[64] => Array ( [day] => 04/10/2019 [totalprice] => 235.00 )
[65] => Array ( [day] => 05/10/2019 [totalprice] => 235.00 )
[66] => Array ( [day] => 06/10/2019 [totalprice] => 235.00 )
[67] => Array ( [day] => 07/10/2019 [totalprice] => 235.00 )
[68] => Array ( [day] => 08/10/2019 [totalprice] => 235.00 )
[69] => Array ( [day] => 09/10/2019 [totalprice] => 235.00 )
[70] => Array ( [day] => 10/10/2019 [totalprice] => 235.00 )
[71] => Array ( [day] => 11/10/2019 [totalprice] => 235.00 )
[72] => Array ( [day] => 12/10/2019 [totalprice] => 235.00 )
[73] => Array ( [day] => 13/10/2019 [totalprice] => 235.00 )
[74] => Array ( [day] => 14/10/2019 [totalprice] => 235.00 )
[75] => Array ( [day] => 15/10/2019 [totalprice] => 235.00 )
[76] => Array ( [day] => 16/10/2019 [totalprice] => 235.00 )
[77] => Array ( [day] => 17/10/2019 [totalprice] => 235.00 )
[78] => Array ( [day] => 18/10/2019 [totalprice] => 235.00 )
[79] => Array ( [day] => 19/10/2019 [totalprice] => 235.00 )
[80] => Array ( [day] => 20/10/2019 [totalprice] => 235.00 )
[81] => Array ( [day] => 21/10/2019 [totalprice] => 235.00 )
[82] => Array ( [day] => 22/10/2019 [totalprice] => 235.00 )
[83] => Array ( [day] => 23/10/2019 [totalprice] => 235.00 )
[84] => Array ( [day] => 24/10/2019 [totalprice] => 235.00 )
[85] => Array ( [day] => 25/10/2019 [totalprice] => 235.00 )
[86] => Array ( [day] => 26/10/2019 [totalprice] => 235.00 )
[87] => Array ( [day] => 27/10/2019 [totalprice] => 235.00 )
[88] => Array ( [day] => 28/10/2019 [totalprice] => 235.00 )
[89] => Array ( [day] => 29/10/2019 [totalprice] => 235.00 )
[90] => Array ( [day] => 30/10/2019 [totalprice] => 235.00 )
[91] => Array ( [day] => 31/10/2019 [totalprice] => 235.00 )
)
Со следующим кодом:
foreach($blankarray as $rate){
if ($rate['totalprice'] == '0'){
} else {
$firstrate = $rate['totalprice'];
if ($firstrate != $previousrate) {
$firstdate = $rate['day'];
echo '<br>'.$firstdate;
echo '</br><font color="green"> <b>'.$firstrate .'</b></font>';
$previousrate = $firstrate;
}
Я получаю:
01/08/2019
585.00
01/09/2019
410.00
01/10/2019
235.00
Как можноЯ добавляю предыдущую дату, когда итоговая цена меняется, чтобы я мог иметь:
01/08/2019
31/08/2019
585.00
01/09/2019
30/09/2019
410.00
01/10/2019
31/10/2019
235.00