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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:04:54+00:00 2026-05-27T22:04:54+00:00

I have an array that contain the values north, east, south or west. For

  • 0

I have an array that contain the values north, east, south or west.

For example I got an array containing:

['south', 'west', 'north']

Now I would like to sort the array in a custom order like: north, then east, then south, then west.

So in my example the values should be in this order:

['north', 'south', 'west']

How can I do that?

  • 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-27T22:04:54+00:00Added an answer on May 27, 2026 at 10:04 pm

    You could also use array_intersect(). It preserves the order of the first array. Give an array of all cardinal directions in the correct order as the first parameter and the array to sort as the second.

    $cardinals = array( 'north', 'east', 'south', 'west' );
    $input = array( 'south', 'west', 'north' );
    
    print_r( array_intersect( $cardinals, $input ) );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array that could contain zero values. $array = array(3=> 1000, 5=>
How would I filter through an array and return values that contain a certain
I have an array that contains the RGB colour values for each pixel in
Lets say I have an array numbers that contains the following values: int numbers
I have an array of Linq objects of type Link that contains values as
I have an array of buttons that contain the id's of the buttons. I
I have a struct array called AnalysisResults , that may contain any MATLAB datatypes,
i have an array that can contain the same value more than once. What
I have a string and it can contain values like this $string = '1,2,3,4,5';
I have an ArrayList of type String that contain certain values. I want to

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.