php如何删除单个数组,如何在php中使用array_splice删除单个数组成员?
我想我可能無法正確理解array_splice應(yīng)該如何工作.我的理解是第一個參數(shù)是你的初始數(shù)組,第二個參數(shù)是要開始的元素,第三個參數(shù)是要刪除/替換的元素的長度或數(shù)量.
所以,我有這個數(shù)組(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的數(shù)組; TypeFlag = C等)我不想用任何東西替換它;只是為了返回剩下的兩個元素的數(shù)組.我試過這個(其中cart是數(shù)組名稱):
$cart = array_splice($cart, 1,1);
但是當(dāng)我做一個print_r時,我最終得到的是:
Array ( [0] => Array ( [TypeFlag] => C [qty] => 2 [denom] => 25 [certMessage] => [totalPrice] => 50 ) )
所以它似乎是刪除0和2,并留下1作為余數(shù).我究竟做錯了什么?
總結(jié)
以上是生活随笔為你收集整理的php如何删除单个数组,如何在php中使用array_splice删除单个数组成员?的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 本地如何预览php文件上传,如何实现js
- 下一篇: php 判断类存在,PHP怎么判断类是否