php - Format content of array (to match Highcharts requirements) -


i have php array created simple xml object , looks following example (hard-coded demoing):

$arr = array("item1"=>"53","item2"=>"20","item3"=>"7","item4"=>"4","item4"=>"2","item6"=>"2","item7"=>"1"); 

i use array create chart using highcharts requires different format (see below). how can convert content of array match format ?

[['item1',53],['item2',20],['item3',7],['item4',4],['item5',2],['item6',2],['item7',1]] 

many this, mike.

just try with:

$output = json_encode(array_map(function($key, $value){     return array($key, (int) $value); }, array_keys($arr), array_values($arr))); 

output:

string '[["item1",53],["item2",20],["item3",7],["item4",2],["item6",2],["item7",1]]' (length=75) 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -