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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:46:18+00:00 2026-06-05T13:46:18+00:00

I have the following array: items = array( ‘note’ => array(), ‘text’ => array(),

  • 0

I have the following array:

items = array(
        'note' => array(),
        'text' => array(),
        'year' => array()
        )

So I have:

[note] => Array
(
   [0] => 'note1'
   [1] => 'note2'
   [2] => 'note3'
), 
[text] => Array
(
   [0] => 'text1'
   [1] => 'text2'
   [2] => 'test3'
), 
[year] => Array
(
   [0] => '2002'
   [1] => '2000'
   [2] => '2011'
)

And I would like to arrange the above arrays by year. but when moving elements I would like to move the corresponding elements in other arrays(note,text).

For example:

[note] => Array
(
   [2] => 'note3'
   [0] => 'note1'
   [1] => 'note2'
), 
[text] => Array
(
   [2] => 'text3'
   [0] => 'text1'
   [1] => 'test2'
), 
[year] => Array
(
   [2] => '2011'
   [0] => '2002'
   [1] => '2000'
)
  • 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-05T13:46:20+00:00Added an answer on June 5, 2026 at 1:46 pm

    I would first extract the year part and sort it by value, while still maintaining the key, using arsort():

    $yearData = $array['year'];
    arsort($yearData);//sort high-to-low by value, while maintain it's key.
    

    Finally, sort the data using this newly sorted year:

    $newArray['note'] = array();
    $newArray['text'] = array();
    $newArray['year'] = array();
    
    foreach($yearData as $key => $value){
        $newArray['note'][$key] = $array['note'][$key];
        $newArray['text'][$key] = $array['text'][$key];
        $newArray['year'][$key] = $array['year'][$key];
    }
    

    FYI, there are a bunch of functions that deal with sorting arrays in PHP.

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

Sidebar

Related Questions

I have the following PHP array: class MyItems { $items = array( 'note' =>
I have the following 2D array var items = [['al','bv','sd'], ['al','cc','ab'], ['cv','vv','sw'], ['al','bv','sd'] ];
Say we have the following array of instantiated objects: SomeClass[] items = {new SomeClass(Apples,
I have the following array structure in MySQL. There could be no items or
I have the following array Dim items() = { New CheckedListBoxItem(NYC, False), New CheckedListBoxItem(CHI,
I have the following XML <plist version=1.0> <dict> <key>items</key> <array> <dict> <key>assets</key> <array> <dict>
I have the following JSON text to parse in Java: { items: [ {
I have following array: var events = [ {id : 1, start : 100,
I have following array, that I need to operate by hand on bitmaps. const
I have the following array: open_emails = [[2012-04-21, 5], [2012-04-20, 1], [2012-04-22, 4]]; But

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.