PHP switch statement inside for loop
for-loop, php, switch-statement
Solution
You're missing your `break` statement which stops execution of your switch statement. Without it everything "falls through" to the last statement which sets `$pubtitle` to "Pub Title 3";
switch ($pub){
case 'pub1': $pubtitle = "Pub title 1"; break;
case 'pub2': $pubtitle = "Pub title 2"; break;
case 'pub3': $pubtitle = "Pub title 3"; break;
}
Problem
a have very simple problem here is my code: ``` $imax = 3; $licenses = array('pub1','pub2','pub3'); for ($i=0; $i<=$imax; $i++) { $pub = $licenses[$i]; switch ($pub){ case 'pub1': $pubtitle = "Pub title 1"; case 'pub2': $pubtitle = "Pub title 2"; case 'pub3': $pubtitle = "Pub title 3"; } echo $pubtitle; } ``` output is: ``` Pub title 3 Pub title 3 Pub title 3 ``` I trying to put `$pubtitle` to an array, but its not working too :(