Php Programming Code Examples
Php > Function Handling Code Examples
Call User Function
Call User Function
/*
A small difference in these 2 examples one has all arguements in an array param the other uses multiple params
The difference is the function called call_user_func() vs call_user_func_array()
*/
/* Call User Function with Vars */
<?php
function car ($color, $doors) {
if ($doors==4 && $color=="blue")
print "We have no $color 4 door cars, sorry";
else
print "Our $color 5 door cars are only $9999";
}
call_user_func ('car', "blue", 4) . "\n";
call_user_func ('car', "red", 5);
?>
/* Call User Function with Array */
<?php
function debug($var, $val)
echo "***DEBUGGING\nVARIABLE: $var\nVALUE:";
if (is_array($val) || is_object($val) || is_resource($val))
print_r($val);
else
echo "\n$val\n";
echo "***\n";
}
$c = mysql_connect();
$host = $_SERVER["SERVER_NAME"];
call_user_func_array ('debug', array("host", $host));
call_user_func_array ('debug', array("c", $c));
call_user_func_array ('debug', array("_POST", $_POST));
?>