I would like to know what is the quickest and most effective way to make comparisons. This will be more meaningful with my code:
public function exampleChangeVariable ($variable) {
if ($variable == 'notif_received_title') {
$variable = _('Text 1');
}
else if ($variable == 'notif_inprogress_title') {
$variable = _('Text 2');
}
else if ($variable == 'notif_preparation_title') {
$variable = _('Text 3');
}
else if ($variable == 'notif_positif_title') {
$variable = _('Text 4');
}
else if ($variable == 'notif_negatif_title') {
$variable = _('Text 5');
}
else if ($variable == 'notif_accepted_title') {
$variable = _('Text 6');
}
else if ($variable == 'notif_rejected_title') {
$variable = _('Text 7');
}
return $variable;
}
This function is found in a foreach
(data recovered in database) and I would like to optimize it to the maximum.
Should I instead use numbers as a variable?
If I want to use text variables, is length important? (
notif_received_title
would bereceived
)The
else if
is a good choice?How could I do better? (knowing he could have about twenty
if
)