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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:16:30+00:00 2026-06-05T21:16:30+00:00

Here is my array that is put together: Array ( [1] => Array (

  • 0

Here is my array that is put together:

Array
(
[1] => Array
    (
        [0] => Array
            (
                [date] => 1335848400000
                [value] => 1
                [product_id] => 1
                [title] => Test Product
            )

        [1] => Array
            (
                [date] => 1338526800000
                [value] => 8
                [product_id] => 1
                [title] => Test Product
            )

    )

[2] => Array
    (
        [0] => Array
            (
                [date] => 1335848400000
                [value] => 1
                [product_id] => 2
                [title] => Test Product 2
            )

        [1] => Array
            (
                [date] => 1338526800000
                [value] => 4
                [product_id] => 2
                [title] => Test Product 2
            )

    )

[3] => Array
    (
        [0] => Array
            (
                [date] => 1338526800000
                [value] => 6
                [product_id] => 3
                [title] => Test Product 3
            )

    )

)

What I would like it to display as:

{
name: 'Test Product',
data: [[1335848400000, 1],[1338526800000, 8]]
},
{
name: 'Test Product 2',
data: [[1335848400000, 1], [1338526800000, 4]]
},
{
name: 'Test Product 3',
data: [[1338526800000, 6]]
},

I need to group by dates and values together as such for highcharts.

How would I go about doing that? I have no idea where to even start. I have done research into it but couldn’t find a good example.

EDIT:

Working code except with one error:

for($i=0 ; $i<=count($array) ; $i++)
                    {
                    $result_array[$i]['name'] = $array[$i][0]['title'];
                        for($j=0 ; $j<count($array[$i]) ; $j++)
                        {
                            $result_array[$i]['data'][$j][0] = $array[$i][$j]['date'];
                            $result_array[$i]['data'][$j][1] = $array[$i][$j]['value'];
                        }
                    }

                    echo $result = json_encode($result_array);

error:

Severity: Notice

Message: Undefined offset: 0

Filename: name.php

Line Number: 115

[{"name":null},{"name":"Test Product","data":[[1335848400000,"1"],[1338526800000,"8"]]},{"name":"Test Product 2","data":[[1335848400000,"1"],[1338526800000,"4"]]},{"name":"Test Product 3","data":[[1338526800000,"6"]]}] 
  • 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-05T21:16:32+00:00Added an answer on June 5, 2026 at 9:16 pm

    You can use this loop

    <?php
    
    for($i=1 ; $i<=count($main_array) ; $i++)
    {
       $result_array[$i]['name'] = $main_array[$i][0]['title'];
       for($j=1 ; $j<=count($main_array[$i]) ; $j++)
       {
           $result_array[$i]['data'][$j][0] = $main_array[$i][$j]['date'];
           $result_array[$i]['data'][$j][1] = $main_array[$i][$j]['value'];
       }
    }
    
    
    echo $result = json_encode($result_array);
    
    ?>
    

    I have tested it… It works compaletely as you want

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

Sidebar

Related Questions

Noob question here! I have an array with hashes that looks like this: arr
I need to extract Asia from this array. How can i do that. Here
I have an encrypted, base64 encoded array that I need to put into a
I have an array that I declare like this: $health_array = array( ); For
I am trying to put together a function that does the following: retrieve a
I have a Mysql Recordset that I have put into an associative array so
My problem in here ( probably ) is that $db->fetch_array won't show all the
So i have a class name repository which is just a simple array.Here is
if($err) $_SESSION['msg']['login-err'] = implode('<br />',$err); Three quick questions: Why use a two-dimensional array here?
$.getJSON(./data/revenue-item-data.php,{val:'val'},function(data){ $('#totalUnits').val(data[0].SUM(item_qty)); $('#totalAmounts').val(data[0].SUM(DISTINCT net_total)); }); Here is array I get for above code: [{SUM(item_qty):68,SUM(DISTINCT

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.