当前位置:网站首页>php如何去掉数组键值
php如何去掉数组键值
2022-04-21 11:46:00 【亿速云】
php如何去掉数组键值
这篇文章主要介绍“php如何去掉数组键值”,在日常操作中,相信很多人在php如何去掉数组键值问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”php如何去掉数组键值”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
php去掉数组键值的方法:1、使用“array_keys($array)”语句,可去掉全部键值,返回包含全部键名的数组;2、使用“array_splice($array,$start,$length)”语句,可去掉指定位置的一个或多个键值。

本教程操作环境:windows7系统、PHP7.1版、DELL G3电脑
php中去掉数组键值有多种方法,下面介绍两种方法:
方法1:使用array_keys()函数
array_key() 函数可以获取数组中的部分或所有键名。
利用array_key() 函数可去掉数组的全部键值,返回包含全部键名的新数组。
使用语法:
array_keys($array)
示例:
<?phpheader("Content-type:text/html;charset=utf-8");$arr=array("Name"=>"Peter","Age"=>"41","Country"=>"USA");var_dump($arr);$keys=array_keys($arr);var_dump($keys);?>

方法2:使用array_splice()函数
array_slice() 函数用来截取数组,也就是从数组中提取出一个片段
使用语法:
array_splice($array,$start,$length)
参数:
array 表示要截取的数组。
start 表示开始截取的位置(下标):
如果 start 为正数,则从前往后截取。
如果 start 为负数,则从距离 arr 末端 -start 的位置开始,从后往前截取。例如 -2 意味着从数组的倒数第二个元素开始。
length 是可选参数,表示截取长度:
如果 length 为正数,那么表示截取的元素个数;
如果 length 为负数,那么截取的片段将终止在距离数组末端 length 的位置;
如果省略,那么将从 start 位置开始,一直截取到数组的末尾。
使用array_splice()函数可去掉指定位置的一个或多个键值。
示例1:
<?phpheader("Content-type:text/html;charset=utf-8");$arr=array(10,12,20,25,24);echo "原数组:";var_dump($arr);echo "删除后的数组:" ;array_splice($arr,2);var_dump($arr);?>

示例2:
<?phpheader("Content-type:text/html;charset=utf-8");$arr=array(10,12,20,25,24);echo "原数组:";var_dump($arr);echo "删除后的数组:" ;array_splice($arr,2,-1);var_dump($arr);?>

到此,关于“php如何去掉数组键值”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!
版权声明
本文为[亿速云]所创,转载请带上原文链接,感谢
https://www.yisu.com/zixun/694165.html
边栏推荐
- 关于 winform GridView 的操作
- Applet static attribute assignment and dynamic attribute assignment
- 1. Precision marketing practice Alibaba cloud odpscmd precision marketing data processing
- [binary number] symmetric binary tree
- fixed定位失效,transform影响普通元素
- 分库和分表
- Conversion between localdate, localdatetime and date
- L2-004 这是二叉搜索树吗? (25 分)
- MQ相关流程及各项内容
- 如何跨域请求携带 cookie ?
猜你喜欢

Leaflet military plotting - Assault direction modification (leaflet chapter. 90)

Detailed explanation of kubernetes (II) -- kubernetes structure and resource object

循环队列的长度「In DataStructure」

UNIX philosophy and high concurrency

Xinghan will become the co construction unit of finops industry promotion matrix in the future

Normalized records in pycharm

Chalk technology implements the Omo integration mode, and the dual core drives the rapid growth of revenue

解决方案| 快对讲调度系统:高效协作

L2-005 集合相似度 (25 分)(set+容斥)

实现浏览器多标签页通信
随机推荐
手撕链表题,我看你也行(1)
L2-003 月饼 (25 分)(贪心)
如何跨域请求携带 cookie ?
【链表】148. 排序链表
Solution | fast intercom dispatching system: efficient cooperation
Huisheng Huiying 2022 releases 8 new features of Huisheng Huiying 2022 (official)
Kubernetes详解(二)——Kubernetes结构与资源对象
2. Precision marketing practice Alibaba cloud odpscmd data feature project
Redis cluster mode
连接服务器报错No supported authentication methods available
苹果硬件技术高级副总裁揭露:自研 M1 太难了
54000 stars all return to zero. Project Author: I regret it very much
Dynamics CRM 365 在Plugins调用外部接口报错:请求'System.Net.WebPermission,System,Version=4.0.0.0,Culture=neutral,PublicKey=b77a5c5561934e089'类型的权限已失败
Nocalhost for dapr remote debugging
IIR second order filter in flight control
How to carry cookies in cross domain requests?
Encryption and decryption using RSA
IDEA的LeetCode力扣插件设置
redis面试问题
互联网快讯:拓荆科技成功登陆科创板;极米H3S、极米Z6X Pro持续热销;盒马在上海启动“流动超市”