I'm looking to manipulate an array that was generated from a MySQL query. The print_r format returns the following:
Array ( [cols] => Array ( [0] => Array ( [label] => time [type] => number ) [1] => Array ( [label] => quantity [type] => number ) ) [rows] => Array ( [0] => Array ( [c] => Array ( [0] => Array ( [v] => 8.8 ) [1] => Array ( [v] => 3 ) ) ) [1] => Array ( [c] => Array ( [0] => Array ( [v] => 8.2 ) [1] => Array ( [v] => 4 ) ) ) [2] => Array ( [c] => Array ( [0] => Array ( [v] => 7.3 ) [1] => Array ( [v] => 1 ) ) ) [3] => Array ( [c] => Array ( [0] => Array ( [v] => 5.7 ) [1] => Array ( [v] => 3 ) ) ) [4] => Array ( [c] => Array ( [0] => Array ( [v] => 4.9 ) [1] => Array ( [v] => 2 ) ) ) [5] => Array ( [c] => Array ( [0] => Array ( [v] => 2.9 ) [1] => Array ( [v] => 1 ) ) ) [6] => Array ( [c] => Array ( [0] => Array ( [v] => 1.6 ) [1] => Array ( [v] => 1 ) ) ) ) )
I put this output into the array beautifier here in order to better understand the structure: http://phillihp.com/toolz/php-array-beautifier/
However, even with this prettier version, I'm unsure how to access specific elements. For example, how would I return just the pair of "8.2","4" bolded above from this array? Any insight into this structure would be greatly appreciated.
Here's the code that generated this array:
$return_structure = array(
'cols' => array (
// array('label' => 'name', 'type' => 'string'),
array('label' => 'time', 'type' => 'number'),
array('label' => 'quantity', 'type' => 'number')
),
'rows' => array()
);
while($row = mysql_fetch_assoc($result)) {
$return_structure['rows'][] = array('c' => array(
//array('v' => $row['name']),
array('v' => $row['time']),
array('v' => $row['quantity']),
));
Thanks in advance for any assistance!! -Daniel
<pre>
tag if you're debugging with prints. It should keep whitespace andprint_r
will have correct formatting. – Grashlok Apr 1 '14 at 21:25