As I want to plot some temperature graphs with the Google Chart Library I am building an Array in PHP to encode it to JSON as described in
https://developers.google.com/chart/interactive/docs/reference#methods
The first entry of "dataTable['cols']" is the x-axis. I then want to add some more lines one by one.
This works:
$dataTable = array();
$dataTable['cols'] = array(
array('id' => 'time_axis', 'label' => 'Time', 'type' => 'datetime')
);
foreach($sensors as $id => $description) {
//Entries in $sensors are from a database
$column = array('id' => $id, 'label' => $description, 'type' => 'number');
array_push($dataTable['cols'],$column);
}
This does not (500 Server Error):
$dataTable = array();
$dataTable['cols'] = array(
array('id' => 'time_axis', 'label' => 'Time', 'type' => 'datetime')
);
foreach($sensors as $id => $description) {
//Entries in $sensors are from a database
$column = array('id' => $id, 'label' => $description, 'type' => 'number');
$dataTable['cols'][] = $column;
}
When I'm reading the accepted answer here
PHP add elements to multidimensional array with array_push
right, it should be equivalent.