Shift an entire array to the by one position in php

Viewed 1837

For example: I have an array that looks like this: Array ( [0] => A [1] => B [2] => C [3] => D [4] => E [5] => F). and etc..

I want to push the entire array by 1 to the right, so it looks like this: ( [0] => 0 [1] => A [2] => B [3] => C [4] => D [5] => E [6] => F). and etc....

Edit: My bad. I didn't word my question properly. I'm hoping I don't confuse people trying to clarify. I'd like to continue to push the array until the end of the array length. For example $len is 7. I'd like to perform an action on the array before iterating to the next position. So it looks like this:

Array ( [0] => 0 [1] => 0 [2] => 0 [3] => 0 [4] => 0 [5] => 0 [6] => A).

My first attempt at this problem was to create a for loop:

for ($i = 0; $i < $len; $i++) {
  echo $chars[$i + 1];
  array_unshift($chars, 0);
}

My loop gives me 7 B's, which isn't what I want.

Is what I'm describing possible?

2 Answers
Related