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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:19:00+00:00 2026-06-06T04:19:00+00:00

Given the following array: $array = array( ‘note’ => array(‘test’, ‘test1’, ‘test2’, ‘test3’, ‘test4’),

  • 0

Given the following array:

   $array = array(
        'note' => array('test', 'test1', 'test2', 'test3', 'test4'),
        'year' => array('2011','2010', '2012', '2009', '2010'),
        'type' => array('journal', 'conference', 'editorial', 'conference','conference'),
    );

Array can be easily transformed if it is more easier using the following function:

for($i=0; $i < count($array['type']); $i++)
  foreach($array as $key=> $value)
    $temp[$i][$key] = $value[$i];

print_r($temp);

And I want to sort it using the following criteria:

  1. An array $sortby = ('journal', 'editorial', 'conference')
  2. After sorting in categories I would like to sort by year DESC for every category.

Desired result:

Array
(
[note] => Array
    (
        [0] => test
        [1] => test2
        [2] => test1
        [3] => test4
        [4] => test3
    )

[year] => Array
    (
        [0] => 2011
        [1] => 2012
        [2] => 2010
        [3] => 2010
        [4] => 2009
    )

[type] => Array
    (
        [0] => journal
        [1] => editorial
        [2] => conference
        [3] => conference
        [4] => conference
    )

)
  • 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-06T04:19:02+00:00Added an answer on June 6, 2026 at 4:19 am
    <?php 
    $Array= array(array('note'=>'test1','year'=>'2011','type'=>'journal'),
                  array('note'=>'test2','year'=>'2012','type'=>'editorial'),
                  array('note'=>'test3','year'=>'2012','type'=>'conference'),
                  array('note'=>'test4','year'=>'2012','type'=>'conference'),
                  array('note'=>'test5','year'=>'2012','type'=>'conference'));
    print_r($Array);
    /*Array
    (
        [0] => Array
            (
                [note] => test1
                [year] => 2011
                [type] => journal
            )
    
        [1] => Array
            (
                [note] => test2
                [year] => 2012
                [type] => editorial
            )
    
        [2] => Array
            (
                [note] => test3
                [year] => 2012
                [type] => conference
            )
    
        [3] => Array
            (
                [note] => test4
                [year] => 2012
                [type] => conference
            )
    
        [4] => Array
            (
                [note] => test5
                [year] => 2012
                [type] => conference
            )
    
    )*/
    
    //Lets sort them by value
    function array_sort_by_column(&$arr, $col, $dir = SORT_DESC) {
        $sort_col = array();
        foreach ($arr as $key=> $row) {
            $sort_col[$key] = $row[$col];
        }
        return array_multisort($sort_col, $dir, $arr);
    }
    
    array_sort_by_column($Array, 'year');
    print_r($Array);
    /*Array
    (
        [0] => Array
            (
                [note] => test2
                [year] => 2012
                [type] => editorial
            )
    
        [1] => Array
            (
                [note] => test3
                [year] => 2012
                [type] => conference
            )
    
        [2] => Array
            (
                [note] => test4
                [year] => 2012
                [type] => conference
            )
    
        [3] => Array
            (
                [note] => test5
                [year] => 2012
                [type] => conference
            )
    
        [4] => Array
            (
                [note] => test1
                [year] => 2011
                [type] => journal
            )
    
    )*/
    
    
    array_sort_by_column($Array, 'note');
    print_r($Array);
    /*
    Array
    (
        [0] => Array
            (
                [note] => test5
                [year] => 2012
                [type] => conference
            )
    
        [1] => Array
            (
                [note] => test4
                [year] => 2012
                [type] => conference
            )
    
        [2] => Array
            (
                [note] => test3
                [year] => 2012
                [type] => conference
            )
    
        [3] => Array
            (
                [note] => test2
                [year] => 2012
                [type] => editorial
            )
    
        [4] => Array
            (
                [note] => test1
                [year] => 2011
                [type] => journal
            )
    
    )*/
    
    array_sort_by_column($Array, 'type');
    print_r($Array);
    /*
    Array
    (
        [0] => Array
            (
                [note] => test1
                [year] => 2011
                [type] => journal
            )
    
        [1] => Array
            (
                [note] => test2
                [year] => 2012
                [type] => editorial
            )
    
        [2] => Array
            (
                [note] => test3
                [year] => 2012
                [type] => conference
            )
    
        [3] => Array
            (
                [note] => test4
                [year] => 2012
                [type] => conference
            )
    
        [4] => Array
            (
                [note] => test5
                [year] => 2012
                [type] => conference
            )
    
    )
    
    */
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

// given following array: $data = array( 0=>array( data=>object1, col=>array( 0=>array( data=>object2, col=>array( 0=>array(
Given following array: var arr = [undefined, undefined, 2, 5, undefined, undefined]; I'd like
Given the following array a : a = [1, 2, 3, 4, 5] How
Given the following array of json objects: var items = [ {id:1, parentId:0, name:'item1'},
Given the following Markov Matrix: import numpy, scipy.linalg A = numpy.array([[0.9, 0.1],[0.15, 0.85]]) The
Given the following two indexed arrays: $a = array('a', 'b', 'c'); $b = array('red',
Given the following dates: 6/30/2010 - 7/6/2010 and a static variable: $h = 7.5
Given the following array array( 0 => array( 'id' => '54'), 1 => array(
Can you help me out with this question please. Question: Given the following array
Given the following array: Array ( [143] => Car #1 [144] => Car #2

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.