|
本文分享一些在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);
?>登录后复制 |
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号