i have:
echo $test->getNum1();
echo $test->getNum2();
echo $test->getNum9();
how can i make something:
for(i=0;i<10;i++){
echo $test->getNum . $i .();
}
?
i have:
echo $test->getNum1();
echo $test->getNum2();
echo $test->getNum9();
how can i make something:
for(i=0;i<10;i++){
echo $test->getNum . $i .();
}
?
for(i=0;i<10;i++){
$method = 'getNum' . $i;
echo $test->$method();
}
getNum() with an argument. Just sayin' ;)As a complement to Alex's answer, you can also specify a variable name for a function by using call_user_func or call_user_func_array. These take a callback as their first argument, so you can provide a string within this. In this case you could do something like the following:
for($i=0; $i<10; $i++){
$method = array($test, 'getNum' . $i);
echo call_user_func($method);
}
for ($i = 0; $i < 10; $i++) {
echo eval('$text->getNum'.$i.'()');
}
eval is evil ;)eval, even if it is not the optimal solution. Please check the mindless fearmongering.