Hello,

I have built an array as below.
As you can see the intention is to build the whole alphabet in inner [0] key values and a subsequent "replacement" letter in [1] key value.

I want to move "reverse" or "forward" all of the inner keys-[0] without touching other values.
So, where there is 'a', it becomes 'z' , 'b' ->'a', etc..

How do I dynamically update innner all key-[0] values? I can access all of the inner key-[0] values and have put them in another array where I have done the rotation using array_shift.
But now I am unable to change the elements of all inner key-[0] values from the new array.

Any help will be appreciated.

Thank you,
Vinay

Array
(
    [0] => Array
        (
            [0] => a
            [1] => b
            [2] => 3
            [3] => III
        )

[1] => Array
    (
        [0] => b
        [1] => d
        [2] => 3
        [3] => III
    )

[2] => Array
    (
        [0] => c
        [1] => f
        [2] => 3
        [3] => III
    )

[3] => Array
    (
        [0] => d
        [1] => h
        [2] => 3
        [3] => III
    )

[4] => Array
    (
        [0] => e
        [1] => j
        [2] => 3
        [3] => III
    )

[5] => Array
    (
        [0] => f
        [1] => l
        [2] => 3
        [3] => III
    )

[6] => Array
    (
        [0] => g
        [1] => c
        [2] => 3
        [3] => III
    )

[7] => Array
    (
        [0] => h
        [1] => p
        [2] => 3
        [3] => III
    )

    Sorry, but I'm not sure what you are trying to achieve. Please provide example input and output.

      $arrayname[2][1]='k'

      will change the f entry to a k

      or to swap items 1 and 2 :
      $foo=$arrayname[2][0];
      $bar=$arrayname[2][1];

      $arrayname[2][0]=$bar;
      $arrayname[2][1]=$foo;

      (you can avoid one of those intermediate swaps, but above makes it obvious)
      Or you could do it with array_shift if you want, but you still have to insert the other value at position '1', so the simple direct assignment is less trouble

        Write a Reply...