I have an array which has keys starting from 0 upwards. Is there a way to reindex the array to change shift the keys to start from 3 instead of 0?
Asked
Active
Viewed 57 times
0
-
are you going to answer any answer ?? – Alireza Fallah Jan 11 '14 at 10:39
2 Answers
1
Quickly off the top of my head, but there's probably better ways to do it
$reindexedArray = array_combine(
range(3,count($originalArray)+3),
$originalArray
);

Mark Baker
- 209,507
- 32
- 346
- 385
0
$newArray = array();
foreach($myArray as $key=>$value){
$newArray[$key+3] = $value;
}
print_r($newArray);

Alireza Fallah
- 4,609
- 3
- 31
- 57