Ligthers Ligthers - 4 days ago 8
Javascript Question

Convert array into string if array is within an array using javascript/php

I have a scenario wherein I need to get all [microtime] in the array result which is processed using an ajax.

Here's the process


  1. On dropdown change, I take the value and apply it in MySQL query.

  2. It will return an array.



I was able to print_r the result.

But I want to get all [microtime] and all [sum(srp)]

enter image description here

Is there a possible way to do that.

Like, I want the result to be like this:
**microtime is converted to months <----this I already did

var months = [January,February,March..blablabla]
var sum = [396484,629103,blablablabla]

Answer

Use a foreach loop on your results and store the separate pieces in separate arrays.

$months = $sums = array();
foreach ($results as $result) {
    $months[] = getMonthFromMicrotime($result['microtime']); // Using your custom function here
    $sums[] = $result['SUM(srp)'];
}
Comments