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 6628037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:05:03+00:00 2026-05-25T22:05:03+00:00

I need to reorder an array so that all slugs get loaded before parents,

  • 0

I need to reorder an array so that all slugs get loaded before parents, but only if a parent has a value that matches a slug value exactly.

For example, take this array:

Array ( 
    [0] => Array ( 
        [parent] => information_desk_3 
        [slug] => about_dream_portal_1 
    )
    [1] => Array ( 
        [parent] => forum
        [slug] => information_desk_3 
    )
    [2] => Array ( 
        [parent] => about_dream_portal_1 
        [slug] => testing_2
    )
    [3] => Array ( 
        [parent] => testing_2 
        [slug] => information_desk_4 
    )
)

I need it so that it gets ordered as follows:

Array ( 
    [0] => Array ( 
        [parent] => forum
        [slug] => information_desk_3 
    )
    [1] => Array ( 
        [parent] => information_desk_3 
        [slug] => about_dream_portal_1 
    )
    [2] => Array ( 
        [parent] => about_dream_portal_1 
        [slug] => testing_2
    )
    [3] => Array ( 
        [parent] => testing_2 
        [slug] => information_desk_4 
    )
)

But the catch is, it needs to search through all slugs and reorder them so that the slugs come first in the array, before the parents that match the value of that slug. Please someone help me, I’ve been at it for hours now to no avail.

  • 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-05-25T22:05:03+00:00Added an answer on May 25, 2026 at 10:05 pm

    Sounds like what you really have is a graph, and you want a partial ordering of nodes. That means you can solve the problem using standard graph algorithms.

    If you build a tree of items where each parent knows about all its children then you can do a breadth-first traversal of the tree to build your partially ordered output.

    In your example it’s a very simple graph:

    forum -> information_desk_3 -> about_dream_portal_1 -> testing_2 -> information_desk_4
    

    If you start at forum and walk down the tree adding nodes to the output list as you go then you’ll wind up with the correct order.

    If you have multiple disjoint trees then it gets a little trickier, but still shouldn’t be too hard. You just need to figure out which nodes are root nodes and then walk each tree in turn.

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

Sidebar

Related Questions

I need to reorder an multidimensional array in php but I can't get it
I need to reorder a plist (an array of dictonaries) by Key value. In
I need to reorder this array by the 'score' value (descending) array 21 =>
I need to reorder a collection The final results should be that all the
I have the following array, I need to reorder it by average rating descending.
Need to an expression that returns only things with an I followed by either
I need to just do a quick match and replace all that comes from
I need to reorder an array in PHP. The array: Array ( [0] =>
I need to reorder the fields in a modelform that came from another base
I need to do an arbitrary reorder of a 7 bit value (Yes I

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.