Need help with a small problem that I just don't understand. Example code (in a for-loop): switch($something) { case 'Apple': $fruit="APP";break; case 'Banana': $fruit="BAN";break; case 'Orange': $fruit="ORA";break; } $fruitarray[$i]=$fruit; Code (markup): $fruitarray will then only contain the first letter (A,B or O) of the string. What am I missing? Thank you
Try something like this. // make a dictionary instead of a switch $fruitkeys = array('Apple' => 'APP', 'Banana' => 'BAN', 'Orange' => 'ORA'); // do whatever in for loop for (...) { $fruitarray[$i] = $fruitkeys[$something]; } // debug print_r($fruitarray); PHP: Doing so, you don't have to do a switch, will shave off some microseconds.
Solved. I know it was something silly. I accidentaly uses the same variable for two different things.