Heim  >  Artikel  >  Backend-Entwicklung  >  php 自定义函数的例子

php 自定义函数的例子

WBOY
WBOYOriginal
2016-07-25 08:56:51953Durchsuche
本文分享一些在php中自定义函数的一些简单例子,有需要的朋友,可以作个参考。

1,php自定义函数的例子

<html>
<head>
<title>定义一个函数</title>
</head>
<body>
<?php
function bighello(){
     print "<h1>HELLO!</h1>";
}
bighello();
?>
 </body>
</html>

2,在页面上打印文本的自定义函数

<HTML>
  <HEAD>
  <TITLE>打印文本-bbs.it-home.org</TITLE>
  </HEAD>
  <BODY>
  <?php
  function textonweb ($content, $fontsize) {
     echo "<FONT SIZE=$fontsize>$content</FONT>";
  }
  textonweb ("A <BR>", 7);
  textonweb ("AA. <BR>", 3);
  textonweb ("AAA. <BR>", 3);
  textonweb ("AAAA! <BR>", 3);
  ?>
  </BODY>
</HTML>

3,声明一个简单的php自定义函数

<?php
  function aFunction(){
      print "音乐是生活的一种方式";
  }
  aFunction();
?>

4,从字符串创建自定义函数

<?
$lambda =create_function('$a,$b','return(strlen($a)-strlen($b));');
$array = array('really long string here,boy', 'this', 'middling length',
               'larger');
usort($array,$lambda);
print_r($array);
?>


Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn