php函数指定默认值方法的小例子_PHP教程

WBOY
Libérer: 2016-07-13 17:18:14
original
932 Les gens l'ont consulté

本节内容:
php函数指定默认值
在php编程中,为自定义函数设定默认值,当用户调用该函数时,如果不给参数指定值,参数会用默认值顶替。
例1,

复制代码 代码如下:



php函数指定默认值-www.jb51.net


function printMe($param = NULL)
{
   print $param;
}
printMe("This is test");
printMe();
?>


输出结果:
This is test
例2,php函数参数默认值的使用范例,php函数参数中设置和使用默认值。
代码:

复制代码 代码如下:


 
  php函数参数默认值 - www.jb51.net
 
 
    function textonweb ($content, $fontsize=3){
     echo "$content";
  }
  textonweb ("A
", 7);
  textonweb ("AA.
");
  textonweb ("AAA.
");
  textonweb ("AAAA!
");
  ?>
 
 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/621698.htmlTechArticle本节内容: php函数指定默认值 在php编程中,为自定义函数设定默认值,当用户调用该函数时,如果不给参数指定值,参数会用默认值顶替...
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!