Home > Backend Development > PHP Tutorial > Example of php custom function

Example of php custom function

WBOY
Release: 2016-07-25 08:56:51
Original
1027 people have browsed it
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>
Copy after login

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>
Copy after login

3. Declare a simple php custom function

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

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);
?>
Copy after login


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template