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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T02:58:49+00:00 2026-05-20T02:58:49+00:00

First time posting here after having great results searching for other answers on stackoverflow.

  • 0

First time posting here after having great results searching for other answers on stackoverflow. I’ve hit a roadblock in an app I’m trying to build. It involves plotting a graph with JS using dynamic values pulled from a database.

I’m at the point now where I have all the values I need to plot a graph using a javascript library. The basic requirement to plot a graph is a basic array that looks something like this:

var plot1 = [ [2,15], [4,23], [5,25] ];

In my case of [x,y] x = date and y = clicks. With that data, you could call the function like so:

$.plot($("#placeholder"), [ plot1 ];

This does all the work for you and builds a nice little graph. In my case I do all of this dynamically. Here’s where I’m stuck. I have an array that outputs this when printed:

Array ( 
    [0] => var test7 = [[1, 1]]; 
    [1] => var test2 = [[1, 1]]; 
    [2] => var test2 = [[4, 1]]; 
    [3] => var test2 = [[15, 2]]; 
    [4] => var test1 = [[2, 1]]; 
    [5] => var test1 = [[6, 7]]; 
    [6] => var test1 = [[14, 1]]; 
    [7] => var test1 = [[15, 1]]; 
    [8] => var giver = [[3, 2]]; 
    [9] => var giver = [[14, 1]]; 
    [10] => var test4 = [[4, 1]]; 
);

What I need to do now, is group all of the values that contain the same linkId (test2 has 3 instances for example) together into one line. Here’s what I need the array to look like:

Array ( 
    [0] => var test7 = [[1, 1]]; 
    [1] => var test2 = [ [1, 1], [4, 1], [15, 2] ]; 
    [4] => var test1 = [ [2, 1], [6, 7], [14, 1], [15, 1] ]; 
    [8] => var giver = [ [3, 2], [14, 1] ]; 
    [10] => var test4 = [[4, 1]]; 
);

From that point I can run a foreach on it an echo out the values inside a script tag, and we’re up and running!

Suggestions? I know there isn’t going to be a single built in function that accomplishes everything I need in one quick swoop. array_unique() is close but not quite what I need. I think I can use array_walk($array, callback) which accepts an array and a callback function that is executed on each value within the array, but I’m really not sure where to go from there.

Any help is greatly appreciated!

  • 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-20T02:58:50+00:00Added an answer on May 20, 2026 at 2:58 am
    $array = array( 
      'var test7 = [[1, 1]];', 
      'var test2 = [[1, 1]];', 
      'var test2 = [[4, 1]];', 
      'var test2 = [[15, 2]];', 
      'var test1 = [[2, 1]];', 
      'var test1 = [[6, 7]];', 
      'var test1 = [[14, 1]];', 
      'var test1 = [[15, 1]];', 
      'var giver = [[3, 2]];', 
      'var giver = [[14, 1]];', 
      'var test4 = [[4, 1]];' 
    );
    
    foreach ($array as $val) {
      preg_match('~var ([^ ]+) = \[\[([^\]]+)~',$val,$var);
      $tArray[$var[1]][] = "[".$var[2]."]";
    }
    $array = array();
    foreach ($tArray as $key => $val) {
      $array[] = 'var '.$key.' = ['. implode(',',$val) . '];';
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

first time SO user :) I know that I can format a number like
The first time I load the website in the production web server, it start
The first time I try to open a particular form many of the controls
This is my first time attempting to call an ASP.NET page method from jQuery.
This is my first time using joomla. I don't know if I'm using the
Long time listener, first time caller. I'm a full time SE during the day
This is my first time with Web services. I have to develop web services
Every time you start Visual Studio, the first time you click Add Reference to
When loading a page for the first time (!IsPostback), I am creating a button
I have just installed C# for the first time, and at first glance it

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.