Php getting started knowledge point 7 basic application of PHP functions _ php getting started _ script house

Source: Internet
Author: User
Php getting started knowledge point 7: Basic Application of PHP functions, which are very common. You can take a look.

Php getting started knowledge point 7: Basic Application of PHP functions, which are very common. You can take a look.

The Code is as follows:
/*
* Simple functions
*/
Function fontBold ($ con ){
Return" $ Con";
}
$ Str = "simple function test! ";
Echo "plain text: $ str
";
Echo "bold text:". fontBold ($ str )."";
/*
* Functions with optional parameters
*/
Function fontColor ($ con, $ color = "bule "){
Return "$ con ";
}
$ 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" $ Con";
}
$ 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! ")
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.