migran Posted August 1, 2008 Share Posted August 1, 2008 Hi, I am looking at numerical integration with PhP. To write an algorithm is not a problem for me, but as i am new to php i just cant figure the syntax out. Can i have function as an argument for another function? i want to have function numerical integrator being able to integrate different functions... something like: <?php echo 'look here>>>', myzed(4), integrator(myzed); function integrator(func($a)) { global func some code bla bla bla $aa=func($a)-func($b) bla bla bla echo $aa } function myzed($z) { global $omega; echo $omega*$z; } ?> Link to comment https://forums.phpfreaks.com/topic/117757-numerical-integration-with-php/ Share on other sites More sharing options...
migran Posted August 1, 2008 Author Share Posted August 1, 2008 just found something that can be useful. http://uk2.php.net/manual/en/functions.variable-functions.php Link to comment https://forums.phpfreaks.com/topic/117757-numerical-integration-with-php/#findComment-605680 Share on other sites More sharing options...
Barand Posted August 1, 2008 Share Posted August 1, 2008 you can't use your syntax but you can do this <?php function product ($a, $b) {return $a * $b;} function sum ($a, $b) {return $a + $b;} function mycall($fn, $v1, $v2) { return $fn ($v1,$v2); } $a = 3; $b = 4; $f = 'sum'; echo mycall($f, $a, $b); // 7 $f = 'product'; echo mycall($f, $a, $b); // 12 ?> Link to comment https://forums.phpfreaks.com/topic/117757-numerical-integration-with-php/#findComment-605786 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.