As a matter of code speed / efficiency, which method is faster on execution?
(the number has been reduced to 5 for demonstrative simplicity)
Method 1:
$chance = rand (0,5);
switch($chance){
case 0:
$chance = 'axe'; break;
case 1:
$chance = 'handle'; break;
case 2:
$chance= 'beak'; break;
case 3:
$chance= 'hammer'; break;
case 4:
$chance= 'snow'; break;
case 5:
$chance= 'bird'; break;
default: echo 'Error...'; break;
}
Method 2:
$translate = array(0=>'axe', 1=>'handle', 2=>'beak', 3=>'hammer', 4=>'snow', 5=>'bird');
$chance = strtr(($chance = rand (0,5)), $translate);