Home  >  Article  >  Backend Development  >  Example of php custom function

Example of php custom function

WBOY
WBOYOriginal
2016-07-25 08:56:51953browse
This article shares some simple examples of custom functions in PHP, which can be used as a reference for friends in need.

1, Example of php custom function

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

2, Custom function to print text on the page

<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. Declare a simple php custom function

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

4, Create custom function from string

<?
$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);
?>


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