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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:56:24+00:00 2026-06-02T15:56:24+00:00

Given an associative array like the following, $field_defaults = array( ‘id’ => 0, ‘name’

  • 0

Given an associative array like the following,

$field_defaults = array(
  'id' => 0,
  'name' => 'new item',
  'desc' => '',
  'parent_id' => 0,
);

can I rely on array_keys() returning the keys in the order they were specified? Or, more precisely, since arrays in PHP seem to have a stable order, as per this answer, are the keys returned by array_keys() in the same order as they appear in the input array? The manual page doesn’t give any hints.

When I try this, they seem to respect the original order, but I would like to be able to rely on that behaviour.

  • 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-02T15:56:26+00:00Added an answer on June 2, 2026 at 3:56 pm

    TL;DR: Theoretically you can’t count on it; for practical purposes IMO you can.


    Since the docs do not guarantee the ordering then technically the correct answer would be “no, you can’t count on that”.

    That’s because theoretically the developers could have chosen to reserve themselves the option of changing the implementation at a future date so that it does not honor the existing order any more (perhaps to improve performance, or to gain some other benefit).

    Now as a practical matter, we know that the current implementation honors the ordering — PHP arrays are ordered containers (there is a linked list of values among other things) — and this is something you wouldn’t ever expect to change.

    If it did, the change would hint to a corresponding significant change in the internal implementation of arrays and that would in turn be likely to break lots of other code too. I don’t see it happening any time soon.

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

Sidebar

Related Questions

Given an associative array (of the sort returned by jQuery.serializeArray() ) like this: [
Given a PHP associative array like this one: $a = array( 'color' => 'red',
Given this XML: <?xml version=1.0 encoding=utf-8?> <content dataType=XML> <item type=Promotion name=Sample Promotion expires=04/01/2009> <![CDATA[
Is it possible to return groups as an associative array? I'd like to know
Say that I have an array like the following: Array ( [arm] => Array
I've been given an array that needs to be sorted by its key (associative
Given 2 associative arrays: $fruits = array ( d => lemon, a => orange,
Given a package, how can I automatically find all its sub-packages?
Given an NSApp object (aka [NSApplication sharedApplication]), how can I get the currently active
For example, I have an array like this: array(4) ( a => string(0) b

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.