当前位置:网站首页>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
边栏推荐
- The principle and common methods of multithreading and the difference between thread and runnable
- Filter usage of spark operator
- ESP32编译环境的搭建
- Distinct use of spark operator
- PS为图片添加纹理
- JSP learning 2
- Upgrade MySQL 5.1 to 5.610
- Intersection, union and difference sets of spark operators
- TIA博图——基本操作
- [key points of final review of modern electronic assembly]
猜你喜欢

Force buckle - 198 raid homes and plunder houses

捡起MATLAB的第(5)天

Master vscode remote GDB debugging

Sort by character occurrence frequency 451

第九天 static 抽象类 接口

第十天 异常机制

捡起MATLAB的第(9)天

Partitionby of spark operator

Day (8) of picking up matlab

New developments: new trends in cooperation between smartmesh and meshbox
随机推荐
Grbl learning (II)
实现缺省页面
Construction of esp32 compilation environment
homwbrew安装、常用命令以及安装路径
Solution to the fourth "intelligence Cup" National College Students' IT skills competition (group B of the final)
299. 猜数字游戏
Day (7) of picking up matlab
JS regular determines whether the port path of the domain name or IP is correct
gps北斗高精度卫星时间同步系统应用案例
Jour (9) de ramassage de MATLAB
Compile, connect -- Notes
第十天 异常机制
Hypermotion cloud migration helped China Unicom. Qingyun completed the cloud project of a central enterprise and accelerated the cloud process of the group's core business system
撿起MATLAB的第(9)天
Day (2) of picking up matlab
linux上启动oracle服务
What does cloud disaster tolerance mean? What is the difference between cloud disaster tolerance and traditional disaster tolerance?
保姆级Anaconda安装教程
Basic greedy summary
一文掌握vscode远程gdb调试