本文介紹了PHP刪除數組的第一個索引并重新索引的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
限時送ChatGPT賬號..
我有一個像數組
<代碼>([0] =>一個[2] =>乙[4] =>C[6] =>D)
我想刪除第一個元素,然后重新索引數組以獲得輸出
<代碼>([0] =>乙[1] =>C[2] =>D)
我需要使用哪個 PHP 函數?
<小時>更新
輸入數組是
數組([0] =>大批([0] =>一些不需要的文字[1] =>你瘋了)[2] =>大批([0] =>我下面的文字[1] =>你瘋了)[10] =>大批([0] =>我愛的名言[1] =>你瘋了))
輸出應該像
數組([0] =>大批([0] =>我下面的文字[1] =>你瘋了)[1] =>大批([0] =>我愛的名言[1] =>你瘋了))
解決方案
With array_splice.
http://www.php.net/manual/en/function.array-splice.php
<前>php > print_r($input);大批([0] => A[2] => B[4] => C[6] => D)php > array_splice($input, 0, 1);php > print_r($input);大批([0] => B[1] => C[2] => D)I have an array like Array
(
[0] => A
[2] => B
[4] => C
[6] => D
)
I want to remove the first element and then re-index array to get the output
(
[0] => B
[1] => C
[2] => D
)
Which PHP function i need to use?
Update
Input array is
Array
(
[0] => Array
(
[0] => Some Unwanted text
[1] => You crazyy
)
[2] => Array
(
[0] => My belowed text
[1] => You crazyy
)
[10] => Array
(
[0] => My loved quote
[1] => You crazyy
)
)
And the output should be like
Array
(
[0] => Array
(
[0] => My belowed text
[1] => You crazyy
)
[1] => Array
(
[0] => My loved quote
[1] => You crazyy
)
)
解決方案
With array_splice.
http://www.php.net/manual/en/function.array-splice.php
php > print_r($input); Array ( [0] => A [2] => B [4] => C [6] => D ) php > array_splice($input, 0, 1); php > print_r($input); Array ( [0] => B [1] => C [2] => D )
這篇關于PHP刪除數組的第一個索引并重新索引的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!