0
$metodo = array(
"1"=> fazMetodo1(), //retorna algum valor
"2"=> fazMetodo2(), //retorna algum valor
"3"=> fazMetodo3() //retorna algum valor
//... assim vai
);
$inputId = "2";
if (array_key_exists($inputId , $metodo )) {
$metodo[$inputId];
}
//Por switch-case
$inputId = "2";
switch($inputId){
case "1":
fazMetodo1();
break;
case "2":
fazMetodo2();
break;
case "3":
fazMetodo3();
break;
}
the problem: Once array starts, all methods will return something, there is an alternative way to do it other than by switch case?
What do you mean by "giant parole" (speaking of quantities, of course)?
– user28595
This, if I have a switch with many cases, there is another alternative?
– carlos
Explain better what your problem is. The alternative you have already given. Otherwise it has a huge gambit, so it is better not to do.
– Maniero
I thought there was a better alternative, the problem is that it will run all methods as soon as array is started (would that be the gambiarra?), rs
– carlos