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

  • Home
  • SEARCH
  • 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 7877329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:20:27+00:00 2026-06-03T03:20:27+00:00

I need array keys in json array to be integers. Now they are strings.

  • 0

I need array keys in json array to be integers. Now they are strings. Could you tell me where is my mistake?

   $i = 0;
   while($i < 7) {
       isset($ips[date('d', $week_start + $i * 86400)])
           ? $ips[(int)date('d', $week_start + $i * 86400)] = count(date('d', $week_start + $i * 86400))
           : $ips[(int)date('d', $week_start + $i * 86400)] = 0;

       isset($time[date('d', $week_start + $i * 86400)])
           ? $time[(int)date('d', $week_start + $i * 86400)] = count(date('d', $week_start + $i * 86400))
           : $time[(int)date('d', $week_start + $i * 86400)] = 0;

       $i++;
   }

   return json_encode(array('unique' => $time, 'impressions' => $ips));
  • 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-03T03:20:28+00:00Added an answer on June 3, 2026 at 3:20 am

    What you want is not possible with json_encode or json format

    Look at this 2 arrays

    $array = array("A","B","C","D");
    $array2 = array(2=>"A",7=>"B",11=>"C",70=>"D");
    

    Run

     var_dump($array,$array2);
    

    Output

    array
      0 => string 'A' (length=1)
      1 => string 'B' (length=1)
      2 => string 'C' (length=1)
      3 => string 'D' (length=1)
    array
      2 => string 'A' (length=1)
      7 => string 'B' (length=1)
      11 => string 'C' (length=1)
      70 => string 'D' (length=1)
    

    You can see in PHP the are both Array

    Now run

     var_dump(json_encode($array),json_encode($array2));
    

    Output

    string '["A","B","C","D"]' (length=17)
    string '{"2":"A","7":"B","11":"C","70":"D"}' (length=35)
    

    Conclusion

    If you are setting array keys and those keys does not start with 0 and increase serially it would be encoded as json object

    If you want just arrays

     var_dump(json_encode(array_values($array2)));
    

    Output

     string '["A","B","C","D"]' (length=17)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to change this array's keys to 0-5, why isn't this working? $arr
I have a PHP 2D array, many keys, each with one value, I need
I need to remove from an array some keys. $array = array('a' => 'a',
I have an array that has sequential array keys and I need to randomly
I have an array with several elements. The array keys are numeric. I now
Possible Duplicate: Do PHP array keys need to we wrapped in quotes? Is it
I need to combine the keys from an array, with the values in another
Basically I have this string $str=word1 word2 word3; I need array( 'word1', 'word2', 'word3'
I need an array where size is known at compile time. I know I
I need an array to hold member-function-pointers of different classes. How can I define

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.