3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $strings = array('SS2014', 'SU2014','FW2014','FW2013', 'SU2013','SS2013'); $cleanUpResult = array(); $counter = 0; $previousYear = ''; $currentIndex = 10; foreach($strings as $row){ if($counter == 0){ $previousYear = substr($row, -4); } var_dump($previousYear); if($previousYear !== substr($row, -4)){ $currentIndex += 10; } var_dump($previousYear); if($counter > 0){ $previousYear = substr($row, -4); } var_dump(substr($row, 0, 1)); switch(substr($row, 0, 1)){ case 'SS': $cleanUpResult[$currentIndex + 1] = $row; break; case 'SU': $cleanUpResult[$currentIndex + 2] = $row; break; case 'FW': $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; } $cleanUpResult[] = $row; $counter++; } var_dump($cleanUpResult);
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
string(4) "2014" string(4) "2014" string(1) "S" string(4) "2014" string(4) "2014" string(1) "S" string(4) "2014" string(4) "2014" string(1) "F" string(4) "2014" string(4) "2014" string(1) "F" string(4) "2013" string(4) "2013" string(1) "S" string(4) "2013" string(4) "2013" string(1) "S" array(6) { [0]=> string(6) "SS2014" [1]=> string(6) "SU2014" [2]=> string(6) "FW2014" [3]=> string(6) "FW2013" [4]=> string(6) "SU2013" [5]=> string(6) "SS2013" }