Summary of commonly used array and string functions in PHP

小云云
Release: 2023-03-20 13:18:01
Original
5457 people have browsed it

This article mainly shares with you a summary of commonly used array and string functions in PHP, hoping to help everyone.

Commonly used string functions:

//去除字符串首尾空格和特殊字符
trim()
//截取字符串
substr() 、mb_substr()
//查找指定字符串在目标字符串中首次出现的位置
strpos()
//查找指定字符串在目标字符串中最后一次出现的位置
strrpos()
//替换字符串
str_replace()
substr_replace()
//计算字符串长度
strlen()
//转义 和 还原 字符串  (', '', \ , NULL )
addslashes()
stripslashes()
//重复字符串
str_repeat()
//打乱字符串
str_shuffle()
//分割字符串
explode()
数组常用函数
//创建数组
array()
//创建指定范围内数组
range()
//检查数组中是否存在某个值
in_array()
//检测变量是否是数组
is_array()
//计算数组中元素个数
count()
// 获取数组中部分或所有键名
array_keys()
// 获取数组中所有的值
array_values()
 
// 计算数组中所有值的和
array_sum()
//搜索给定值的键名
array_search()
//从数组中随机取出一个或多个单元
array_rand()
//数组排序
sort()      [不保持索引]
asort()     [保持索引]
//打乱数组
shuffle()
//拆分数组
array_chunk()
//合并数组
array_merge()
//将元素压入数组末尾(入栈)
array_push()
Copy after login

Related recommendations:

Summary of common PHP array (Array) functions

Summary of examples of commonly used array array functions in PHP [assignment, splitting, merging, calculation, adding, deleting, querying, judging, sorting]

Commonly used array functions in PHP Summary (reprint)

The above is the detailed content of Summary of commonly used array and string functions in PHP. 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template