M
M
Miku Hatsune2017-05-26 22:28:39
PHP
Miku Hatsune, 2017-05-26 22:28:39

How to iterate an array backwards?

I will briefly describe the task, there is an array:

{
    0 => "One",
    1 => "Two",
    2 => "Three"
}

It needs to be converted to:
{
    0 => "Three",
    1 => "Two",
    2 => "One"
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Immortal_pony, 2017-05-26
@Hatsune-Miku

array_reverse

T
Therapyx, 2017-05-26
@Therapyx

$max = sizeof($array);
for($i = max; $i > 0 ;$i--)
{
echo $array[i];
}

a... and save.
$array= array_reverse($array);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question