php - Reindex array by increasing and decreasing all of top indexes -


first, have list have found

how remove array element , re-index array?

php reindex array?

they did not make sense in case. have fallen ridiculous request , i've force find way out, please don't ask me why want that.

i have below array

$input = array(           0=>array('a', 'b'=>array('c')),           1=>array('b', 'c'=>array('d')),           2=>array('c', 'd'=>array('e')),         ); 

i want increase of keys 1 or decrease 1 (acceptable index negative int number)

here expected result

//after increased 1 $input = array(           1=>array('a', 'b'=>array('c')),           2=>array('b', 'c'=>array('d')),           3=>array('c', 'd'=>array('e')),         ); 

or

//after decreased 1 $input = array(           -1=>array('a', 'b'=>array('c')),           0=>array('b', 'c'=>array('d')),           1=>array('c', 'd'=>array('e')),         ); 

the closet answer got here raina77ow in question how increase 1 keys in array?

$arr = array_flip(array_map(function($el){ return $el + 1; }, array_flip($arr))); 

but works simple array key pairs, if array value other array instead of string or integer, raise exception

array_flip(): can flip string , integer values! 

the thing think handling array swap roster manually, final way if there not other workaround.

any appreciated!

the easiest way use foreach , make new array... this:

$new = array(); foreach($arr $k=>$v) {     $new[$k+1] = $v; // either increase     $new[$k-1] = $v; // or decrease } 

you can perform operation passing original array reference.