怎么使数组的下标从0开始

有时候我们会用到一个数组的键(下标)默认从0开始的需求,让我们来看例子:

 1 array (size=2)
 2   4 => 
 3     array (size=3)
 4       'goods_name' => string '发放是否' (length=12)
 5       'goods_price' => string '1111.00' (length=7)
 6       'goods_nums' => string '111' (length=3)
 7   5 => 
 8     array (size=3)
 9       'goods_name' => string '是范德萨发 ' (length=16)
10       'goods_price' => string '22.00' (length=5)
11       'goods_nums' => string '113' (length=3)

 

 

使用 array_values($数组) 会把数组的键默认从下标0开始  结果:
 1 array (size=2)
 2   0 => 
 3     array (size=3)
 4       'goods_name' => string '发放是否' (length=12)
 5       'goods_price' => string '1111.00' (length=7)
 6       'goods_nums' => string '111' (length=3)
 7   1 => 
 8     array (size=3)
 9       'goods_name' => string '是范德萨发 ' (length=16)
10       'goods_price' => string '22.00' (length=5)
11       'goods_nums' => string '113' (length=3)

 

posted @ 2019-08-31 11:51  PHP--***  阅读(4587)  评论(0编辑  收藏  举报