Question: I'm developing a Google Geochart and I'd like it to be dynamic. This is the static code to make the array to store the two values are as follows. The Country is the unique identifier for the map and the colour value is what the colour of the map will be. (Irrelevant but context) 

```
  arrayData = [['Country','Color Value'],
  ['China',3],
  ['Russia',2.6],
  ['France',2.5],
  ['Spain',2.4],
  ['Portugal',1.1]

```

I'd like to be able to make this array from a for loop taken from php echo values. Something like this pseudo code;

```
for (i in range table.length)

 arrayData = [['Country','Color Value'],

 [<?php echo $statements["Country"]; ?>], [<?php echo $statements["Color_Value"]; ?>], 

```

So similar to a php table as it gets all the values, I would like to do the same but for a JavaScript array. Any advice would be kind! 

EDIT: The static code is an example, I want to take values from the database, the first value being country and the second value being colour value. BOTH from the database. I suppose in turn making the geochart dynamic

Answer: 
The function you are looking for is `json_encode()`, but it would be more useful if you first structured your input array.

So something like the following:

```
// Some code here to generate $arrayData from $statements, giving the following

$arrayData = [
  ['Country' => 'China', 'Color Value' => 3],
  ['Country' => 'Russia', 'Color Value' => 2.6],
  ['Country' => 'France', 'Color Value' => 2.5],
  ['Country' => 'Spain', 'Color Value' => 2.4],
  ['Country' => 'Portugal', 'Color Value' => 1.1]
];

// Then, once you have generated $arrayData

echo json_encode($arrayData);

```
```
//First you need to check the structure of the result from your database query
//Then Loop through the result Object/Array to get the desired structure
//Most Common way of doing this is foreach loop 

//define an blank array 
$chart = [];

//put your axis tags/ texts in on first index
$chart[] = ['Country', 'Colour Count'];

//let's say $reult stores the data fetched from database

foreach ($result as $key => $value){
    //let's assume $value has field with country name as value 
    //and field colour_count have color count values, so
    // $value->country = Country Name
    //$value->colour_count = Color Count Value
    $chart[] = [$value->country, $value->colour_count];
}
// Once the Loop is finished, you will get an array with your desired format

//$chart = [['Country', 'Colour Count'],['France', 12],['USA',34],.....so on];

```