Copy codeThe Code is as follows: <? Php
/*
* Simple functions
*/
Function fontBold ($ con ){
Return "<B> $ con </B> ";
}
$ Str = "simple function test! ";
Echo "plain text: $ str <br> ";
Echo "bold text:". fontBold ($ str )."";
/*
* Functions with optional parameters
*/
Function fontColor ($ con, $ color = "bule "){
Return "<font color = \" $ color \ "> $ con </font> ";
}
$ Str = "Color Test ";
Echo $ str;
Echo fontColor ($ str. "This is without the color parameter (Blue by default )! ");
Echo fontColor ($ str, "red". "This is a color parameter (red by default !) ");
/*
* Recursive functions
*/
Function chckint ($ Num ){
If ($ Num> 1 ){
Return chckint ($ Num-1 );
} Else if ($ Num <0 ){
Return chckint ($ Num *-1)-1 );
} Else {
If ($ Num> 0 & $ Num <1 ){
Return false;
} Else if ($ Num ){
Return true;
}
}
}
$ Num = 3;
If (chckint ($ Num )){
Echo $ Num. "is an integer! ";
} Else {
Echo $ Num. "Not an integer ";
}
/*
* Dynamic function call
*/
Function write ($ con ){
Echo "$ con ";
}
Function writeBold ($ con ){
Echo "<B> $ con </B> ";
}
$ MyFupnction = "write ";
$ MyFupnction ("this is an example of dynamically calling a function that is not bold! ");
$ MyFupnction = "writeBold ";
$ MyFupnction ("this is an example of dynamic calling! ")
?>