Home  >  Article  >  Backend Development  >  Example of how to specify a default value for a php function

Example of how to specify a default value for a php function

WBOY
WBOYOriginal
2016-07-25 08:55:51787browse
  1. php function specifies the default value -bbs.it-home.org
  2. < ?php
  3. function printMe($param = NULL)
  4. {
  5. print $param;
  6. }
  7. printMe("This is test");
  8. printMe();
  9. ?>
Copy code

Output results: This is test

Example 2, example of using default values ​​of php function parameters, setting and using default values ​​in php function parameters. Code:

  1. php function parameter default value - bbs.it-home.org
  2. < ;?php
  3. function textonweb ($content, $fontsize=3){
  4. echo "$content";
  5. }
  6. textonweb ("A
    ", 7);
  7. textonweb ("AA.
    ");
  8. textonweb ("AAA.
    ");
  9. textonweb ("AAAA!
    ");
  10. ? >
Copy code


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn