Link to home
Start Free TrialLog in
Avatar of derrida
derrida

asked on

adjust an array to send back to an ajax call

hi
i have a results from a python file ( i don't know python it is from someone else) and it looks like that:

["title1" =>1442,"title2" =>16664,"title3" =>555,"title4" =>65,"title5" =>234]

i need to make this into that to show in morris chart:

        $donutvalues = array(
            array( 'label' => "air" , 'value' => 125) ,
            array( 'label' => "light" , 'value' => 40),
            array( 'label' => "rest" , 'value' => 10 )
            );
        echo json_encode($donutvalues );

Open in new window


when i return this to the ajax call it works. so i need to prepare what comes back from the python file to this sort of array.
so i need the titles to be the values of the label, and the numbers to be the values of the value.
Avatar of Gary
Gary
Flag of Ireland image

There is no correlation between

["title1" =>1442,"title2" =>16664,"title3" =>555,"title4" =>65,"title5" =>234]

and the output you posted!?!?!?!
Avatar of derrida
derrida

ASKER

maybe i didn't explained myself correctly, sorry.

title1,2,3, and so on should be placed in the inner arrays where at the moment there is "air","light","rest" and so on.

the numbers should be placed in the inner arrays as the values of the value key.

i need a loop over what comes in and make it return an array like $donutvalues .

thanks for answering
ASKER CERTIFIED SOLUTION
Avatar of Member_2_248744
Member_2_248744
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of derrida

ASKER

full answer and well commented. so it is clear. thanks