Change values in first key from 0 to count(array) - 1

Posted by sologhost on Stack Overflow See other posts from Stack Overflow or by sologhost
Published on 2010-04-03T06:45:41Z Indexed on 2010/04/03 6:53 UTC
Read the original article Hit count: 305

Filed under:
|
|
|

Ok, I have an array like so:

$myArray[32]['value'] = 'value1';
$myArray[32]['type'] = 'type1';
$myArray[33]['value'] = 'value2';
$myArray[33]['type'] = 'type2';
$myArray[35]['value'] = 'value3';
$myArray[42]['value'] = 'value4';
$myArray[42]['type'] = 'type4';

Ok, looking for a quick way to change all numbers in the first key 32, 33, 35, and 42 into 0, 1, 2, and 3 instead. But I need to preserve the 2nd key and all of the values. The array is already ordered correctly, since I ordered it using a ksort, but now I need to reset the array from 0 - count($myArray) - 1 and keep the 2nd key intact and its value as well.

Can someone please help me?

© Stack Overflow or respective owner

Related posts about array

Related posts about key