Detailed explanation of examples of php system functions

小云云
Release: 2023-03-21 12:26:01
Original
1741 people have browsed it

This article mainly shares with you detailed examples of PHP system functions, hoping to give everyone a deeper understanding of system functions.

Array-related functions:
Array key/value operations:
1.array_values($arr)
Returns all the values in the array and creates a numerical index for them
2 .ARRAY_KEYS ($ arr [, 'value' [, true]])
Return all the key names in the array
to the 'value' to indicate the key
to the 'true' for represented the value. === Judgment
3.in_array ('Value', $ Arr [TRUE])
Judging whether there is a value in the array
to TRUE expresses === judgment
4.Rray_key_exists ('key', $arr)
Determine whether there is a certain key in the array
5.array_flip($arr)
. ##
with take a 1 to represent the recursion. ## Count the number of arrays (not commonly used)
using using using substr_count($str,',') - # The number of times a character appears in a string.
array_unique($arr) removes duplicate elements in the array and retains the previous value
Use the callback function to filter the array:
array_filter($arr, callback);
— # Both are passed to the callback function. If true is returned in the callback function, the value will be retained. If false is returned, the value will not be retained.
Array sorting function:

1.sort() 从小到大,不保留键 (升序) 2.rsort() 从大到小,不保留键(降序) 3.asort() 从小到大,保留键 (升序) 4.arsort() 从大到小,保留键(降序) 5.ksort() 按照键,从小到大(升序) 5.krsort() 按照键,从大到小(降序)
Copy after login

Note: There may be errors when sorting mixed type values. Produces unpredictable results
Split, merge, intersection set:
1.array_slice(who to cut, starting position [, how many to cut [, whether to keep the key]])
Who to cut: what to cut Array
Starting position: counting from 0, the elements at the starting position will be retained
[Cut a few]: When not given, the default is to cut to the end

[Whether to keep the key]: Default is false, not retained ;true retains the original key

2.array_splice(&Who to cut, starting position [, How many to cut [, substitutes]])
Who to cut: The array to be cut is passed by reference
Starting position : Counting from 0, the element at the starting position will be retained
[Cut a few]: If not given, it will be cut to the end by default
[Substitute]: Insert the substitute into the original array, it will not Reserved keys
3.array_combine (key array, value array)
Use the value of the key array as the key and the value of the value array as the value;
The length of the two arrays must be the same, otherwise an error will be reported and false will be returned
4.array_merge($arr1[, $arr2, $...])
Merge N arrays;
Note: The keys of strings with the same name will overwrite the previous ones.
Expansion: The plus sign can also merge arrays; keys with the same name will retain the previous value
5.array_intersect($arr1, $arr2[, $...])
Return the values in N arrays, subscripts Keep the previous
6.array_diff($arr1, $arr2[, $...])
Return the elements in $arr1 that are not in other arrays, and the subscripts remain unchanged
Arrays and data structures :

array_pop() 弹出数组中最后一个元素 array_shift() 弹出数组中第一个元素 array_push() 往数组最后追加1个或多个元素 array_unshift() 往数组最前面追加1个或多个元素
Copy after login

use with use using out through through using ’s ’ ’s ’s ’ through out through through ‐‐‐ ‐‐‐‐ Data structure to: Container used to store data
Queue:

##
current() 返回数组当前指针的值 next() 将数组的指针移到下一个,并返回其值 prev() 将数组的指针移到上一个,并返回其值 end() 将数组的指针移到最后,并返回最后一个值 reset() 将数组的指针重置
Copy after login

随机打乱数组
range() 生成指定范围的数组
shuffle() 随机打乱数组
字符串相关
字符串常用输出:
echo 输出一个或多个字符串
print 输出一个字符串
echo和print是一种语言结构,不是一个函数;
用于输出字符串等简单的数据
print_r 打印变量易于理解的信息
就是查看各种类型变量的值
var_dump 打印变量的相关信息
可以看到任意类型的值和类型
printf() 格式化输出字符串
%s 表示字符串
%b 表示二进制数
%o 表示八进制数
%d 表示十进制数
%x 表示十六进制数
%c 表示是个ascii码值
%% 表示一个单纯的%
sprintf() 同上,只是将结果返回,而不是输出
笔试题之echo和print_r的区别:
1.echo是一种语言结构,不是函数,所以效率略高;
2.echo可以同时输出多个字符串,而print_r不可以
3.echo只能输出简单的数据类型,而print_r可以打印复合类型的数据,比如数组、对象等
去除和填充:
ltrim($str[, '要去除的字符列表'])
默认去除左边的空格
rtrim($str[, '要去除的字符列表'])
默认去除右边的空格
trim($str[, '要去除的字符列表'])
默认去除两边的空格
str_pad($str, 长度,填充品)
用一个字符串将另一个字符串填充为指定长度
字符串大小写的转换:
strtolower() 转换为小写
strtoupper() 转换为大写
ucfirst() 首字母大写
ucwords() 单词的首字母大写(空格区分单词)
和HTML标签处理相关的函数:
htmlspecialchars()
将特殊字符转换为实体
htmlentities() 同上,基本不用
老版本里面会将中文一起转了
strip_tags()
去除html标签
nl2br
将\n换行转换为
换行
字符串反转、长度与加密:
strrev()
将字符串颠倒显示
str_shuffle()
将字符串随机打乱
strlen()
统计字符串的长度,utf-8的中文占3个字节
md5()
将字符串进行加密,得到一个32位的加密后的字符串
number_format()
格式化一个数字
只能是1个、2个或者4个参数
字符串比较函数:cmp:compare的简写,比较的意思
strcmp()
比较两个字符串(区分大小写)
strncmp()
比较字符串开头的若干个字符(区分大小写)
strcasecmp()
比较两个字符串(不区分大小写)
strncasecmp()
比较字符串开头的若干个字符(不区分大小写)
字符串的切割与连接:
explode('切割符', $str)
使用一个字符串分割另一个字符串,返回一个数组
implode('连接符', $arr)
将一维数组用指定字符串连接,返回一个字符串
join()
implode的别名
字符串截取:
substr($str, 开始位置, 截多长);
开始位置从0开始数;为负数时表示倒着数!
字符串也有下标:
可以像数组一样通过下标取出字符串的值
但是,最好不要用来取中文
字符串的查找:
提示:用法统一都是($str, '要找的子字符串');
1.strstr($str, '要找的字符串');
返回从子字符串第一次出现的位置开始,到结尾的字符串;
还有个别名:strchr
2.strrchr 返回从子字符串最后一次出现的位置开始,到结尾的字符串
3.strpos($str, '要找的字符串')
返回子字符串第一次出现的索引位置,从0开始;
注意:1个汉字占3个字节
4.strrpos($str, '要找的字符串')
返回子字符串最后一次出现的索引位置
5.stripos()不区分大小写的strpos
字符串的替换
str_replace('找什么', '换成什么', '在哪儿换');
数学函数

ceil() 向上取整 floor() 向下取整 round() 四舍五入 max() 最大 min() 最小 mt_rand() 随机数
Copy after login

相关推荐:

php 常用的系统函数汇总

关于文件系统函数的10篇文章推荐

php常用的系统函数大全

The above is the detailed content of Detailed explanation of examples of php system functions. For more information, please follow other related articles on the PHP Chinese website!

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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!