0

Here is an array example I have.

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

)

I need the order of the sub array to be reversed. I know the function I need to use is "reverse_array" but I do not know how to apply it to an array within an array.

1 Answer 1

4

The function you need to use is array_reverse(), but I'm assuming that's the one you were talking about. To answer your question, you simply specify the array item instead of the main array:

$array[0] = array_reverse($array[0]);
//     ^                         ^

If you instead wish to reverse all sub-arrays in an array, you can use array_map():

$array = array_map('array_reverse', $array);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.