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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:13:01+00:00 2026-06-09T00:13:01+00:00

Hello i have an array in php Array ( [0] => red [1] =>

  • 0

Hello i have an array in php

Array
(
    [0] => red
    [1] => blue
    [2] => green
    [3] => yellow
    [4] => purple
    [5] => white
)

and i want to sort it using that array

Array
(
    [0] => 
    [1] => 0
    [2] => -1
    [3] => -5
    [4] => -5
    [5] => 9
)

so i want the element with the greatest value on the second array to come first on the first array not its value from the second array but the element it self from the first array to move in the first position on the first array! The second bigger to the second place etc.. elements with the same value don’t care me how they will be arranged!

the output i want to get is

Array
    (
        [0] => white
        [1] => blue
        [2] => green
        [3] => yellow
        [4] => purple
        [5] => red
    )
  • 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-09T00:13:03+00:00Added an answer on June 9, 2026 at 12:13 am

    You can use array_multisort() :

    $ar1 = array(/* your SO links */);
    $ar2 = array(/* your numbers */);
    array_multisort($ar2, SORT_DESC, $ar1);
    

    Documentation here

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

Sidebar

Related Questions

I have a PHP array that looks like this: [3] => Hello [7] =>
Hello I have made a PHP script for wordpress that insert new posts using
Hello I was trying to remove objects from object array that I have and
Hello I have an array that looks like this after passing it through uksort()
Hello I have $string1, Array[] and $string2. I want to create a Arraynew[] such
Hello guys I have this code in main.php config file: 'components' => array( '[.........]',
Possible Duplicate: Sorting an associative array in PHP Hello all, I have an array
Suppose that I have a string $var : //php code $var = hello,world,test; $exp
Hello I am using PHP to allow users to upload files and I have
I have a string like that : 0d(Hi)i(Hello)4d(who)i(where)540d(begin)i(began) And i want to make it

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.