使用PHP中的foreach重置连续整数中的数组值[关闭]

问题描述:

Resetting the value of array in contiguous integers(1,2,3,4...) using foreach in PHP

I have a array like(1,3,3,4,5,6)

how can i reset the values like (1,2,3,4,5,6) using foreach loop

使用PHP中的foreach重置连续整数(1,2,3,4 ...)中的数组值 p>

我有一个像(1,3,3,4,5,6)这样的数组 p>

如何重置像(1, 2,3,4,5,6)使用foreach循环 p> div>

$i = 1;
foreach($array as &$item)
  $item = $i++;

See here in action.