3v4l.org

run code in 300+ PHP versions simultaneously
<?php $strings = array('SS2014','SU2014','FW2014','SS2013','FW2013','NW2012'); $cleanUpResult = array(); $counter = 0; $previousYear = ''; $currentIndex = 10; var_dump($strings); foreach($strings as $row){ if($counter == 0){ $previousYear = substr($row, -4); } var_dump('fist row'); var_dump($row); var_dump('counter'); var_dump($counter); var_dump('previous year'); var_dump($previousYear); var_dump('actual year'); var_dump(substr($row, -4)); if($previousYear !== substr($row, -4)){ $currentIndex = $currentIndex + 10; } if($counter > 0){ $previousYear = substr($row, -4); } $part = substr($row, 0, 2); switch($part){ case 'SS': $cleanUpResult[$currentIndex + 1] = $row; break; case 'SU': $cleanUpResult[$currentIndex + 2] = $row; break; case 'FW': var_dump($part, $row); $cleanUpResult[$currentIndex + 3] = $row; break; case 'WI': $cleanUpResult[$currentIndex + 4] = $row; break; case 'XM': $cleanUpResult[$currentIndex + 5] = $row; break; case 'CO': $cleanUpResult[$currentIndex + 6] = $row; break; case 'NW': $cleanUpResult[$currentIndex + 7] = $row; break; default: break; } $cleanUpResult[] = $row; $counter++; } var_dump($cleanUpResult);
Output for 4.3.0 - 4.3.11, 4.4.0 - 4.4.9, 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.7 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 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.27, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
array(6) { [0]=> string(6) "SS2014" [1]=> string(6) "SU2014" [2]=> string(6) "FW2014" [3]=> string(6) "SS2013" [4]=> string(6) "FW2013" [5]=> string(6) "NW2012" } string(8) "fist row" string(6) "SS2014" string(7) "counter" int(0) string(13) "previous year" string(4) "2014" string(11) "actual year" string(4) "2014" string(8) "fist row" string(6) "SU2014" string(7) "counter" int(1) string(13) "previous year" string(4) "2014" string(11) "actual year" string(4) "2014" string(8) "fist row" string(6) "FW2014" string(7) "counter" int(2) string(13) "previous year" string(4) "2014" string(11) "actual year" string(4) "2014" string(2) "FW" string(6) "FW2014" string(8) "fist row" string(6) "SS2013" string(7) "counter" int(3) string(13) "previous year" string(4) "2014" string(11) "actual year" string(4) "2013" string(8) "fist row" string(6) "FW2013" string(7) "counter" int(4) string(13) "previous year" string(4) "2013" string(11) "actual year" string(4) "2013" string(2) "FW" string(6) "FW2013" string(8) "fist row" string(6) "NW2012" string(7) "counter" int(5) string(13) "previous year" string(4) "2013" string(11) "actual year" string(4) "2012" array(10) { [11]=> string(6) "SS2014" [12]=> string(6) "SU2014" [13]=> string(6) "FW2014" [14]=> string(6) "FW2014" [21]=> string(6) "SS2013" [22]=> string(6) "SS2013" [23]=> string(6) "FW2013" [24]=> string(6) "FW2013" [37]=> string(6) "NW2012" [38]=> string(6) "NW2012" }
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 array(6) { [0]=> string(6) "SS2014" [1]=> string(6) "SU2014" [2]=> string(6) "FW2014" [3]=> string(6) "SS2013" [4]=> string(6) "FW2013" [5]=> string(6) "NW2012" } string(8) "fist row" string(6) "SS2014" string(7) "counter" int(0) string(13) "previous year" string(4) "2014" string(11) "actual year" string(4) "2014" string(8) "fist row" string(6) "SU2014" string(7) "counter" int(1) string(13) "previous year" string(4) "2014" string(11) "actual year" string(4) "2014" string(8) "fist row" string(6) "FW2014" string(7) "counter" int(2) string(13) "previous year" string(4) "2014" string(11) "actual year" string(4) "2014" string(2) "FW" string(6) "FW2014" string(8) "fist row" string(6) "SS2013" string(7) "counter" int(3) string(13) "previous year" string(4) "2014" string(11) "actual year" string(4) "2013" string(8) "fist row" string(6) "FW2013" string(7) "counter" int(4) string(13) "previous year" string(4) "2013" string(11) "actual year" string(4) "2013" string(2) "FW" string(6) "FW2013" string(8) "fist row" string(6) "NW2012" string(7) "counter" int(5) string(13) "previous year" string(4) "2013" string(11) "actual year" string(4) "2012" array(10) { [11]=> string(6) "SS2014" [12]=> string(6) "SU2014" [13]=> string(6) "FW2014" [14]=> string(6) "FW2014" [21]=> string(6) "SS2013" [22]=> string(6) "SS2013" [23]=> string(6) "FW2013" [24]=> string(6) "FW2013" [37]=> string(6) "NW2012" [38]=> string(6) "NW2012" }

preferences:
217.62 ms | 405 KiB | 327 Q