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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:39:48+00:00 2026-05-30T09:39:48+00:00

I have a multidimensional array or arrays which I also use in my configuration

  • 0

I have a multidimensional array or arrays which I also use in my configuration file. The file is also manually edited so I want some of the keys to have fixed position. The code reads configuration file with this array, modifies, insert keys etc and then saves it back. On save I sort the keys but now I found that it is not good enough.

Is there any way to have

  • the key 'full_name' always as the first key
  • the key 'version' as second one
  • and the rest of the keys to be sorted alphabetically?

Sample of the array….

array (
  'skroob' => 
  array (
    'ssh' => 'skroob',
    'codebase_path' => '/srv/www/htdocs/imacs/radek/4.0.1',
    'ssh_status' => 'ok',
    'version' => '4.0.1',
    'ssh_last_access' => '2012-Feb-17 10:07:26',
    'edu_url' => 'https://testing/imacs/radek/4.0.1',
    'full_name' => 'skroob 4.0.1',
  ),
  'testing' => 
  array (
    'full_name' => 'My beautiful testing server (trunk)',
    'version' => 'trunk',
    'ssh' => 'testing',
    'codebase_path' => '/srv/www/htdocs/imacs/radek/trunk',
    'ssh_last_access' => '2012-Feb-17 10:07:26',
    'ssh_status' => 'ok',
  ),
)
  • 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-30T09:39:50+00:00Added an answer on May 30, 2026 at 9:39 am

    Here’s one way. It sorts the array alphabetically, by key. Then it reverses the array and unsets the full_name and version keys. Then it adds those keys again, so they get placed at the end of the array. Lastly, it reverses the array again. Kinda hacky but I’m not sure there’s a much better way to do what you’re asking.

    ksort($arr['skroob']);
    
    $arr['skroob'] = array_reverse($arr['skroob']);
    
    $version = $arr['skroob']['version'];
    $full_name = $arr['skroob']['full_name'];
    
    unset($arr['skroob']['full_name'], $arr['skroob']['version']);
    
    $arr['skroob']['version'] = $version;
    $arr['skroob']['full_name'] = $full_name;
    
    $arr['skroob'] = array_reverse($arr['skroob']);
    

    Another solution is to use uksort and write a small callback function. That would probably look a bit more professional.

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

Sidebar

Related Questions

I have a multidimensional array, and I would have multiple arrays within it. Some
how do I make a pointer to a multidimensional array, which have a unknown
I have a multidimensional-array which looks like this: $array = ( [0] => array
I have a string which represents a multidimensional array in the format: [[A, a],
I have a php multidimensional array which looks like this: $fields = array( array('input',
I was wondering how to use array_push to multidimensional arrays? I have a multidimensional
I have a multidimensional array which is the result of a JOIN statement. And
I have a multidimensional array called $songs , which outputs the following: Array (
I have a PHP multidimensional array which will store information depending on parameters input.
I have a multidimensional array which, when echoed in PHP, looks like this: {

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.