* create_function :
This function will create a php function .This function returns a unique function name as a string, or FALSE on error on creation.
Syntax :create_function( string $argument_list , string $function_code )
for example
<?php
$addnumbers = create_function('$no1,$no1', 'return "sum = " . $no1+$no2;');
echo $addnumbers(12,100) . "\n";
?>
output
sum=112
* function_exists
This function can be used to check whether a function is defined or not .It teturn true if the function has been defined
for example
<?php
function myfunction(){
echo "Reached here";
}
$fun='myfunction';
echo function_exists($fun)?" function $fun exist <br>":" $fun doesn't exist <br>";
$fun='myfunction11';
echo function_exists($fun)?" function $fun exist <br>":" $fun doesn't exist <br>";
?>
output :
function myfunction exist
function myfunction11 doesn't exist
* is_callable()
this function checks whether a variable can be called as a function or not
* call_user_func
This function call a user function
syntax: call_user_func ( function ,parameter)
for example
<?php
function egfunction(&$age){
echo $name."\n";
$age++;
}
$age=22;
echo "my age before function call ".$age;
call_user_func('egfunction', $age);
echo "my age after function call ".$age;
?>
output :
my age before function call 22
my age after function call 23
* call_user_func_array
this function call a function with an array of parameters.
for example
<?php
function myfunction($no1, $no2) {
return $no1+ $no2;
};
$func='myfunction';
echo call_user_func_array($func, array(300,500));
?>
output
800
* func_num_args :
This function returns the number of arguments passed to the function,
This function can be used with func_get_arg() and func_get_args() to ensure that the right number of arguments have been passed to a function.
for example
<?php
function sampleFn()
{
$argNo = func_num_args();
echo "Number of arguments: $argNo \n";
}
sampleFn();
sampleFn('only one arg');
sampleFn('two', 'args');
sampleFn(1,2,3,4,5,6,7,8,9,10);
?>
output :
Number of arguments : 0
Number of arguments : 1
Number of arguments : 2
Number of arguments : 10
Note : in javascript we can use arguments.length to find the length
alert(arguments.length);
* func_get_arg
This function returns an item from the argument list.
syntax : func_get_arg ( $num )
<?php
function myfunction()
{
$No = func_num_args();
echo "Number of arguments: $No<br />\n";
if ($No >= 2) {
echo "Third argument is: " . func_get_arg(2) . "<br />\n";
}
}
myfunction ('v1','V2','V3','V4');
?>
output :
Third argument is V3
* func_get_arg
<?php
function myfunction()
{
$no = func_num_args();
echo "Number of arguments: $numargs<br />\n";
$args = func_get_args();
for ($i = 0; $i < $no; $i++) {
echo "Argument". $i+1." is: " . $args[$i] . "<br />\n";
}
}
myfunction ('v1','V2','V3','V4');
?>
output
Argument 1 is V1
Argument 2 is V2
Argument 3 is V3
Argument 4 is V4
[Saturday, June 13, 2009
|
0
comments
]
Popular Posts
- MySQL stored procedure&triggers
- php questions
- Php Questions
- How we canmove into last changed position on info window close event On google map
- Pattern Matching in mysql
- MySQL INDEX
- MYSQL joins
- Jquery based dynamic adding and removal of html elements.
- securing a form with captcha
- Comparing a date with current date
0 comments
Post a Comment
Please put your comments here. your questions, your suggestions, also what went wrong with me.