3v4l.org

run code in 300+ PHP versions simultaneously
<?php $blankarray = 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 ) ); $previousprice = -1; $thisprice = -1; $nextprice = $blankarray[0]['totalprice']; $c = count($blankarray); for ($i = 0; $i < $c; $i++) { $previousprice = $thisprice; $thisprice = $nextprice; $nextprice = ($i == $c - 1) ? -1 : $blankarray[$i+1]['totalprice']; if ($previousprice == 0 || $thisprice == 0 || $nextprice == 0) continue; if ($thisprice != $previousprice) { echo '<br>'.$blankarray[$i]['day']; } if ($thisprice != $nextprice) { echo '<br>'.$blankarray[$i]['day']; echo '</br><font color="green"> <b>'.$blankarray[$i]['totalprice'].'</b></font>' . "\n"; } }
Output for 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
<br>01/08/2019<br>31/08/2019</br><font color="green"> <b>585</b></font> <br>01/09/2019<br>30/09/2019</br><font color="green"> <b>410</b></font> <br>01/10/2019<br>31/10/2019</br><font color="green"> <b>235</b></font>
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 <br>01/08/2019<br>31/08/2019</br><font color="green"> <b>585</b></font> <br>01/09/2019<br>30/09/2019</br><font color="green"> <b>410</b></font> <br>01/10/2019<br>31/10/2019</br><font color="green"> <b>235</b></font>

preferences:
166.09 ms | 402 KiB | 153 Q