当前位置:网站首页>PHP 零基础入门笔记(13):数组相关函数
PHP 零基础入门笔记(13):数组相关函数
2022-04-23 16:08:00 【彭世瑜psy】
数组相关函数
自定义数组打印函数,便于查看
排序函数
按照 ASCII 码排序
sort 对 array 本身按照值(value)升序排序。(下标重排)
rsort 对 array 本身按照值(value)降序排序。
asort 对 array 自身按照升序进行排序(下标保留)
arsort 对 array 本身按照降序排序
ksort 对 array 本身进行按键(key)升序排序。
krsort 对 array 本身按照键(key)降序排序。
shuffle 随机打乱
指针函数
reset 将 array 的内部指针倒回到第一个单元并返回第一个数组单元的值。
end 将 array 的内部指针移动到最后一个单元并返回其值。
next 将数组中的内部指针向前移动一位
prev 将数组的内部指针倒回一位
current 返回数组中的当前值
key 返回数组中当前单元的键名。
注意:next 和 prev 移动指针,可能移出数组,只能通过 end 或者 reset 重置指针
示例
其他函数
count 统计数组、Countable 对象中所有元素的数量
array_push 将 array 当成一个栈,并将传入的变量压入 array 的末尾。
array_pop 弹出并返回 array 最后一个元素的值
array_shift 将 array 的第一个单元移出并作为结果返回
array_unshift 在数组开头插入一个或多个单元
数据结构
- 栈 压栈,FILO先进后出
- 队列 排队,FIFO 先进先出
实现栈:
- 前面 array_unshift/array_shift
- 后面 array_push/array_pop
实现队列:
- 后进前出 array_push/array_shift
- 前进后出 array_unshift/array_pop
array_reverse 返回一个单元为相反顺序的新数组
in_array 检查数组中是否存在某个值
array_keys 返回数组中部分的或所有的键名
array_values 返回 input 数组中所有的值并给其建立数字索引。
版权声明
本文为[彭世瑜psy]所创,转载请带上原文链接,感谢
https://blog.51cto.com/u_13567403/5248596
边栏推荐
- You need to know about cloud disaster recovery
- C#,贝尔数(Bell Number)的计算方法与源程序
- Import address table analysis (calculated according to the library file name: number of imported functions, function serial number and function name)
- Day (3) of picking up matlab
- C language self compiled string processing function - string segmentation, string filling, etc
- js正则判断域名或者IP的端口路径是否正确
- The most detailed knapsack problem!!!
- 捡起MATLAB的第(9)天
- Day (2) of picking up matlab
- [section 5 if and for]
猜你喜欢

Day (5) of picking up matlab

Cloudy data flow? Disaster recovery on cloud? Last value content sharing years ago

5 minutes, turn your excel into an online database, the magic cube net table Excel database

Unity shader learning

Nanny Anaconda installation tutorial

The principle and common methods of multithreading and the difference between thread and runnable

Jour (9) de ramassage de MATLAB

贫困的无网地区怎么有钱建设网络?

R语言中实现作图对象排列的函数总结

JVM - Chapter 2 - class loader subsystem
随机推荐
299. Number guessing game
糖尿病眼底病变综述概要记录
JSP learning 1
shell_ two
Passing header request header information between services through feign
Unity Shader学习
Simple usage of dlopen / dlsym / dlclose
Cloudy data flow? Disaster recovery on cloud? Last value content sharing years ago
Compile, connect -- Notes
RecyclerView advanced use - to realize drag and drop function of imitation Alipay menu edit page
C language self compiled string processing function - string segmentation, string filling, etc
Leetcode-374 guess the size of the number
捡起MATLAB的第(4)天
Install redis and deploy redis high availability cluster
Sort by character occurrence frequency 451
Vim使用Vundle安装代码补全插件(YouCompleteMe)
Grbl learning (II)
Spark 算子之交集、并集、差集
Intersection, union and difference sets of spark operators
Day (4) of picking up matlab