PHP删除数组的第一个索引并重新索引
我有一个像数组
<代码>([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 )
相关文章