php删除array的第一个,如何在php中使用array_splice删除单个数组成员?

我想我可能无法正确理解array_splice应该如何工作.我的理解是第一个参数是你的初始数组,第二个参数是要开始的元素,第三个参数是要删除/替换的元素的长度或数量.

所以,我有这个数组(print_r输出):

Array (

[0] => Array ( [TypeFlag] => S [qty] => 1 [denom] => 25 [certMessage] => [totalPrice] => 25 )

[1] => Array ( [TypeFlag] => C [qty] => 2 [denom] => 25 [certMessage] => [totalPrice] => 50 )

[2] => Array ( [TypeFlag] => V [qty] => 2 [denom] => 25 [certMessage] => test [totalPrice] => 50 ) )

我想完全删除第二个元素(索引为1的数组; TypeFlag = C等)我不想用任何东西替换它;只是为了返回剩下的两个元素的数组.我试过这个(其中cart是数组名称):

$cart = array_splice($cart,1,1);

但是当我做一个print_r时,我最终得到的是:

Array ( [0] => Array ( [TypeFlag] => C [qty] => 2 [denom] => 25 [certMessage] => [totalPrice] => 50 ) )

所以它似乎是删除0和2,并留下1作为余数.我究竟做错了什么?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值