跳转到主要内容
你行网

Main navigation

  • 首页
  • Drupal
  • 编程与开发
  • 数据库
  • 操作系统与应用
  • 服务器与运维
  • 社区
User account menu
  • 登录

面包屑

  1. 首页

php 用户自定义回调函数实例

由 hrs, 1 十一月, 2025

这是一个用户自定义回调函数的实例

首先建立两个函数exclaim 和ask  函数对变量$str  进行加工处理,一个给字符串添加感叹号,一个给字符串添加问号

再建立一个函数printformatted   ,设置两个变量$str ,$format,来接收printformatted函数值,再返回给exclaim 和ask 函数进行加工处理,然后再进行输出。

  1 <!DOCTYPE html>
  2 <html>
  3     <body>
  4 
  5 <?php
  6 
  7 function exclaim($str){
  8 
  9 return $str ."!";  // 对字符串进行加感叹号
 10 
 11 }
 12 
 13 function ask($str){
 14 
 15     return $str ."?";  // 对字符串进行加问号
 16 
 17 }
 18 
 19 function printformatted($str,$format){
 20     //调用$format 回调函数
 21     echo $format($str);
 22 }
 23 printformatted("hello word","exclaim");
 24 echo "<br>";
 25 printformatted("hello word","ask");
 26 
 27 ?>
 28 
 29     </body>
 30 </html>

返回结果

hello word!
hello word?
  • 登录或注册以发表评论
内容类型分类
编程与开发
文章归类
后端开发

文章标签

  • php

评论

文章标签

Excel
CSS
ubuntu
php
vim
五笔
VPN
Linux
command
HTML
drupal 8
drupal 7
centos
composer
Mysql
模块(module)
drush
Drupal
JavaSrcipt
apache
英语
drupal 9
nerdtree
network
果树种植
surround
drupal10
SEO
主题(theme)
二进制
更多

相关文章

  • php json_encode 函数将编码值转为json格式
  • php 回调函数实例
  • 匿名函数(Anonymous Functions)详解
  • foreach 是 PHP 循环语句使用方法
  • implode() 函数的定义和用法
  • 为什么学习php 会一边学,一边忘
  • 在 PHP 中什么是try
  • PHP数据类型及其作用总结
  • php过滤器的作用和说明
  • php 会话使用方法
RSS源

友情链接 网站地图 版权信息 联系我们 网址导航 社区

Copyright © 2019 - 2021 你行网 版权所有  粤ICP备19072650号