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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:44:10+00:00 2026-05-24T08:44:10+00:00

i have an array in the format array() {[2011-07-29]=> 39 [2011-07-30]=> 39 [2011-07-31]=> 39

  • 0

i have an array in the format

array() {[“2011-07-29”]=> 39 [“2011-07-30”]=> 39 [“2011-07-31”]=> 39 [“2011-08-01”]=> 40}

i need to convert it to a string format like this (the below is a var_dump result)

string(584) “[new Date(2011,07,29),39], [new Date(2011, 07, 30),39],[new Date(2011, 07, 31),39], [new Date(2011, 08, 01),40]”

had anyone faced it before , iam stuck with this now…

  • 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-24T08:44:11+00:00Added an answer on May 24, 2026 at 8:44 am
    <?php
        $a = Array("2011-07-29" => 39, "2011-07-30"=> 39, "2011-07-31"=> 39, "2011-08-01"=> 40);
        $sa = array();
        foreach($a as $k => $v){
            $sa[] = "[new Date(".preg_replace('/-/',', ',$k)."),$v]";
        }
        $s = implode(', ',$sa);
        var_dump( $s );
    ?>
    

    Edit: Improved to match better features of @Alvaro’s answer (virtually identical – and answered first), but with simpler string building (I find sprintf an unnecessary layer of abstraction)

    <?php
        $input = array(
            '2011-07-29' => 39,
            '2011-07-30' => 39,
            '2011-07-31' => 39,
            '2011-08-01' => 40,
        );
        $aux = array();
        foreach($input as $date => $number){
            $aux[] = "[new Date(" . str_replace('-',', ',$date) . "),$number]";
        }
        $output = implode(', ', $aux);
        var_dump($input, $output);
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array of dates whose format is like this: 10/15/2005 or 2/10/2011.
How to convert a string format into an array format? I have a string,
I have this code that converts an array of date strings from a format
I have a serialized json string in the format: [{\Version\:\8.63\,\Date\:\07\/11\/2011 00:00:00\,\Count\:213}, {\Version\:\1.0\,\Date\:\07\/11\/2011 00:00:00\,\Count\:1}, .........
i have an array like this: [2011-06-16 16:37:20,23.2], [2011-06-21 16:37:20,35.6], [2011-06-26 16:37:20,41.8], [2011-07-01 16:37:20,25],
I have a string called TheUserTime that looks like this: string TheUserTime = 12.12.2011.16.22;
I have an array in this format: $array = [ ['id' => 117, 'name'
I have array like this: $path = array ( [0] => site\projects\terrace_and_balcony\mexico.jpg [1] =>
An array is defined of assumed elements like I have array like String[] strArray
In JavaScript Language , I have an array ... maybe it look 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.