当前位置:网站首页>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
边栏推荐
- Nanny Anaconda installation tutorial
- 299. Number guessing game
- volatile的含义以及用法
- linux上启动oracle服务
- leetcode-374 猜数字大小
- 5 minutes, turn your excel into an online database, the magic cube net table Excel database
- matplotlib教程05---操作图像
- [key points of final review of modern electronic assembly]
- Using JSON server to create server requests locally
- 糖尿病眼底病变综述概要记录
猜你喜欢
Implement default page
Nanny Anaconda installation tutorial
RecyclerView advanced use - to realize drag and drop function of imitation Alipay menu edit page
299. 猜数字游戏
Matplotlib tutorial 05 --- operating images
Hyperbdr cloud disaster recovery v3 Release of version 3.0 | upgrade of disaster recovery function and optimization of resource group management function
MySQL - MySQL查询语句的执行过程
Tencent offer has been taken. Don't miss the 99 algorithm high-frequency interview questions. 80% of them are lost in the algorithm
Countdown 1 day ~ 2022 online conference of cloud disaster tolerance products is about to begin
5分钟,把你的Excel变成在线数据库,神奇的魔方网表excel数据库
随机推荐
How important is the operation and maintenance process? I heard it can save 2 million a year?
How to conduct application security test (AST)
Application case of GPS Beidou high precision satellite time synchronization system
Distinct use of spark operator
捡起MATLAB的第(9)天
utils. Deprecated in35 may be cancelled due to upgrade. What should I do
Nanny Anaconda installation tutorial
Website pressure measurement tools Apache AB, webbench, Apache jemeter
贫困的无网地区怎么有钱建设网络?
Day (9) of picking up matlab
JS regular détermine si le nom de domaine ou le chemin de port IP est correct
js正则判断域名或者IP的端口路径是否正确
5 minutes, turn your excel into an online database, the magic cube net table Excel database
Construction of esp32 compilation environment
Leetcode-396 rotation function
[open source tool sharing] MCU debugging assistant (oscillograph / modification / log) - linkscope
gps北斗高精度卫星时间同步系统应用案例
Ice -- source code analysis
volatile的含义以及用法
JSP learning 3