たぶんこれはばかげた質問ですが、何が速いのでしょうか?
<?php
function getCss1 ($id = 0) {
if ($id == 1) {
return 'red';
} else if ($id == 2) {
return 'yellow';
} else if ($id == 3) {
return 'green';
} else if ($id == 4) {
return 'blue';
} else if ($id == 5) {
return 'orange';
} else {
return 'grey';
}
}
function getCss2 ($id = 0) {
$css[] = 'grey';
$css[] = 'red';
$css[] = 'yellow';
$css[] = 'green';
$css[] = 'blue';
$css[] = 'orange';
return $css[$id];
}
echo getCss1(3);
echo getCss2(3);
?>
ifステートメントの方が速いと思いますが、質問したいと思います。