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:
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.
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 );
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.
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
full answer and well commented. so it is clear. thanks
["title1" =>1442,"title2" =>16664,"title3" =>555,"title4" =>65,"title5" =>234]
and the output you posted!?!?!?!