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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:31:23+00:00 2026-05-26T13:31:23+00:00

I am wrote an array for all months in a year as follows: $MNTH[01]

  • 0

I am wrote an array for all months in a year as follows:

$MNTH["01"] = "January";
$MNTH["02"] = "February";
$MNTH["03"] = "March";
$MNTH["04"] = "April";
$MNTH["05"] = "May";
$MNTH["06"] = "June";
$MNTH["07"] = "July";
$MNTH["08"] = "August";
$MNTH["09"] = "September";
$MNTH["10"] = "October";
$MNTH["11"] = "November";
$MNTH["12"] = "December";

When I do a variable dump on the keys of $MNTH with var_dump(array_keys($MNTH)),
I get:

array(12) {
 [0]=> string(2) "01"
 [1]=> string(2) "02"
 [2]=> string(2) "03"
 [3]=> string(2) "04"
 [4]=> string(2) "05"
 [5]=> string(2) "06"
 [6]=> string(2) "07"
 [7]=> string(2) "08"
 [8]=> string(2) "09"
 [9]=> int(10)
 [10]=> int(11)
 [11]=> int(12) }

I was expecting strings for the last three keys. How did it become integer? What should I do to correct this phenomenon?

  • 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-26T13:31:24+00:00Added an answer on May 26, 2026 at 1:31 pm

    PHP converts numeric keys to integers at the time you create the array element. It isn’t array_keys that is doing it. But there is a hack to get string numeric keys:

    $a = new stdClass;
    $a->{"0"} = "zero";
    $a = (array) $a;
    var_dump($a);
    

    Output:

    array(1) {
      ["0"]=>
      string(4) "zero"
    }
    

    But you won’t be able to access that key by subscript, so it’s not very useful.

    If you must have string keys, you’ll need to prefix them with another non-numeric (or zero) character:

    $MNTH["001"] = "January";
    $MNTH["012"] = "December";
    

    From the documentation:

    A key may be either an integer or a string. If a key is the standard representation of an integer, it will be interpreted as such (i.e. “8” will be interpreted as 8, while “08” will be interpreted as “08”). Floats in key are truncated to integer. The indexed and associative array types are the same type in PHP, which can both contain integer and string indices.

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

Sidebar

Related Questions

I wrote a recursive function, which returns an array with the paths to all
i wrote a regular merge sort array code and all i want to do
I'm trying to write a 2d array into an output file, it's all working
I have this Array i wrote a function MostFreq that takes an array of
I wrote two queries to find duplicates in the array var groups = from
i have wrote a script to produce an array of data but now want
here's the stored procedure i wrote.In this proc p_subjectid is an array of numbers
I wrote the following algorithm for finding all possible permutations of n unique alphabets.
I just wrote this code to convert a GUID into a byte array. Can
might be a basic one but i wrote a function that selects all from

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.