First, I have to list what I have found
How to Remove Array Element and Then Re-Index Array?
They did not make sense in my case. I have fallen into ridiculous request and I've force to find the way out, then please don't ask me why I want to do 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 to increase all of keys by 1 or decrease by 1 (acceptable to index is negative int number)
Here is expected result
//after increased by 1
$input = array(
1=>array('a', 'b'=>array('c')),
2=>array('b', 'c'=>array('d')),
3=>array('c', 'd'=>array('e')),
);
or
//after decreased by 1
$input = array(
-1=>array('a', 'b'=>array('c')),
0=>array('b', 'c'=>array('d')),
1=>array('c', 'd'=>array('e')),
);
The closet answer I got here from raina77ow in the question How to increase by 1 all keys in an array?
$arr = array_flip(array_map(function($el){ return $el + 1; }, array_flip($arr)));
But it just works with simple array key pairs, if array value is other array instead of a string or integer, it would raise the exception
array_flip(): Can only flip STRING and INTEGER values!
The thing what I could think is handling the array to swap roster manually, it would be the final way if there were not any other workaround.
Any help is appreciated!