As we can define loop templates in C++, for making coding shorter:
#define fo(a,b,c) for( a = ( b ); a < ( c ); ++ a )
Is there any way to d
Disclaimer: Well, this is not exactly preprocessor macro, but due to "dynamic" nature of PHP, preprocessors are not needed/used. Instead however, you are able to wrap functions in other functions, like in the example below.
Yes, you can do this by creating your own function that is being passed also a callback. Here is the example:
// FO function
function fo($b, $c, $callback) {
for ($a = $b; $a < $c; ++$a) {
$callback($a);
}
}
// example of usage
fo(2,10, function($a){
echo '['.$a.']';
});
The above code works in PHP 5.3 and outputs the following:
[2][3][4][5][6][7][8][9]