Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7753525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:04:51+00:00 2026-06-01T12:04:51+00:00

So, array_reverse() is supposed to take an array, and return a copy of it

  • 0

So, array_reverse() is supposed to take an array, and return a copy of it with elements in reverse order, and it’s always been working faithfully for me, up until today. I have an array of arrays, and I need to get them in reverse order, so I’d assumed array_reverse would do exactly what I needed, but it seems to be behaving oddly, and I can’t figure out why.

My initial array (yes, I’m doing some HTML parsing):

Array(
    0 => Array(
        0 => '<blockquote',
        1 => int 232
    ),
    1 => Array(
        0 => '<blockquote',
        1 => int 593
    ),
    2 => Array(
        0 => '<blockquote',
        1 => int 938
    ),
    3 => Array(
        0 => '</blockquote',
        1 => int 2627
    ),
    4 => Array(
        0 => '</blockquote',
        1 => int 2758
    ),
    5 => Array(
        0 => '</blockquote',
        1 => int 2794
    ),
)

running array_reverse($arr) on it, one would expect the returned array to be:

Array (
    0 => Array(
        0 => '</blockquote',
        1 => int 2794
    ),
    1 => Array(
        0 => '</blockquote',
        1 => int 2758
    ),
    2 => Array(
        0 => '</blockquote',
        1 => int 2627
    ),
    3 => Array(
        0 => '<blockquote',
        1 => int 938
    ),
    4 => Array(
        0 => '<blockquote',
        1 => int 593
    ),
    5 => Array(
        0 => '<blockquote',
        1 => int 232
    ),
)

However, it returns an unaltered array. Now, if I do array_reverse($arr[0]), then it reverses the entire array like I want.

I can think of no reason it would not be reversing the initial array, and why, when passing a specific key, it would reverse the entire array, rather than that one sub-array. Why would it be doing this?

EDIT: I walked away and came back, looked at it, and realized the main array had a single element which was the array I’d posted above. Just a good ol’ ID-10-T error.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T12:04:52+00:00Added an answer on June 1, 2026 at 12:04 pm

    However, it returns an unaltered array.

    It should just work.

    Now, if I do array_reverse($arr[0]), then it reverses the entire array like I want.

    Are you sure you don’t have an extra level in your array?? I’m pretty sure you have an extra level!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to reverse the order of an Array in java. What is
I'm look to naturally sort an array, in reverse order and not preserve the
Note: This is asking for the reverse of the usual tuple-to-array conversion. I have
Array.Copy and Buffer.BlockCopy both do the same thing, but BlockCopy is aimed at fast
What kind of algorithm Array.Reverse(string a), uses behind the scene to reverse the string?
I'm looking for a clean way to reverse the order of a Doctrine_Collection. I
Regarding passing arrays to functions and then manipulating the array contents (Array.Reverse) and then
Is there an SPL Reverse array iterator in PHP? And if not, what would
Why is the following code Array.Sort(values); Array.Reverse(values); much faster at sorting an array in
What's the best way to sort an Enumerable in descending order? I've been doing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.