php中最神奇的东西---函数
2020-06-08 05:29
645 查看
php中最神奇的东西—函数
- 1.初始函数
- 1.1函数的分类 函数有3类{
自定义函数{ 自定义函数,其实就是编程语言的开源模块也是各大编程语言得以被大范围应用的根本原因,每个人可以打包函数成模块然后供其他人调用。当然函数作为个人来说是一个结构化设计的模块,同时被多个文件引用。在php中使用函数库中定义的函数需要include() include_once() require require_once把函数加载在文件中。 }递归函数{
递归函数又称为自我调用函数,在执行过程中会调用自己一般加附加条件→判断调用。
}变量函数{ 变量函数又称为可变函数php脚本会寻找和 变量名字一样的并且去执行它。 }
1.1.2第一个自定义函数
```<?php test(); function test() { echo 1; } ```> `每次我们调用函数都需要test()就可以了。 那么我们如果需要传一些参数呢? <?php test() function test($chongba = "none") { echo chongba; } > 传一个数组 <?php test() function test($chongba = "", $arry_aaa = "") { var_dump($array_aaa); } > test("",[1,2,3,4,]) > ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200414200432571.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQwNzg0NTE1,size_16,color_FFFFFF,t_70) 1. [ ] 2. 注意名字不可以与系统函数做冲突比如system,login ```php 在这里插入代码片
1.1.3 几个有意思的函数
- 判断函数是否存在=function_exists()
function test() { return 1; } var_dump(function_exists("test"));
-
2变量
2.1局部变量和全局变量:
fp:
$id = 1; function test() { $id = 2; echo $id; } test();
我们这里的2就是局部变量,再看
function test() { global $id; $id = 23; echo $id; } $id = 122; test();
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200414202706231.png)
输出全局变量global值
2.2
删除变量Unset
fp:
function test() { global $id; $id = 23; echo $id; echo "!!!!!!!!!!!!!!!!!!"; $ie = 100; echo $ie; } $id = 122; test();
我们删除一个变量id
function test() { $id = 232; echo $id; unset($id); echo "!!!!!!!!!!!!!!!!!!"; $ie = 100; echo $ie; } $id = 122; test();
第二次$id赋值失败
2.3 永不会失效的static变量,静态变量。
function test(){ static $a=44; echo $a; echo $a++; } test();
2.4字符串变量string
var_dump(Chr(1));
Ceil(float)浮点型四舍五入
var_dump(ceil(1.222222222222222));
伪类型参数
Empty
var_dump(empty($a));
获取数组 fun_get_args
function more_args() { for($i=0; $i<func_num_args(); $i++) { //使用for循环遍历数组$args echo "第".$i."个参数是".func_get_arg($i)."<br>";//分别输出传入函数的每个参数 } } more_args("one", "two", "three", 1, 2, 3);
相关文章推荐
- php中一个神奇的函数extract
- PHP 神奇的sprintf函数
- PHP两个经典.传神.高级.神奇的函数.
- PHP中喜欢的神奇函数
- php正则表达式及涉及函数
- php中的curl 网页抓取函数
- php header()函数的使用
- 【PHP】操作图片函数实例
- PHP时间戳函数总结
- PHP启动windows应用程序、执行bat批处理、执行cmd命令的方法(exec、system函数详解)
- PHP常用基础函数汇总(可以)
- PHP防止SQL注入自带函数分析
- 利用PHP str_replace()函数替换符合百度MIP内容标准
- php使用curl函数提示Call to undefined function curl_init()
- PHP进阶(一)——数组与函数
- php常用函数
- PHP 使用header函数设置HTTP头的示例方法 表头
- php 用 curl函数发送post请求
- PHP常用函数