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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:02:01+00:00 2026-06-04T15:02:01+00:00

Ive got 2 arrays, first one contains values of objects, and second one contains

  • 0

Ive got 2 arrays, first one contains values of objects, and second one contains their IDs.

In this form:

$values[0] applies to $ids[0]
$values[1] applies to $ids[1]

I need to sort first array (using sort() ) from lowest to highest (values are ints) – That’s not problem.
Problem is, that When I sort array with values, I will lost ID of that value.

My question is: How to make that

If $values[0] turns to $values[5], automatically turn $ids[0] to $ids[5]

Thanks

Update:

Content of $values and $ids:

$values[0] = 1.5;
$values[1] = 2.4;
$values[2] = 15.7;
$values[3] = 11.7;
$values[4] = 4.8;
$values[5] = 0.4;

$ids[0] = 1;
$ids[1] = 2;
$ids[2] = 3;
$ids[3] = 4;
$ids[4] = 5;
$ids[5] = 6;
  • 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-04T15:02:03+00:00Added an answer on June 4, 2026 at 3:02 pm

    Combine the arrays first, then sort by key:

    $newArr = array_combine($ids, $values);
    ksort($newArr);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm in trouble with this one. I've got a bunch of arrays decide on
I've got a class with many string arrays. I'd like to have one generic
I've got an array in perl which contains sorted non-contiguous values. For example: 1
I've got a string like this: #################### Section One #################### Data A Data B
I've got a group of data that looks like this: 001 001 One 001
I've got a collection of strings, and I need to know the first index
Ok so heres what I need to do. I've got a file that contains
I've got two separate arrays which look like this 12-Jan-12 (remove), 14-Mar-12 (remove) £139,
Huge fan of this website, but it's my first post! I've got an array
I've got a .php page showing a HTML table similar to this one :-

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.