[Solved] JavaScript array to dictionary conversation based on count

function convert(data){ var myMap = {} data.forEach(el => myMap[el] = myMap[el] != undefined ? myMap[el] + 1 : 1); return Object.keys(myMap).map(k => {return {name: k, y: myMap[k]}}) } console.log(convert([‘A’,’B’,’B’,’B’,’C’,’C’,’A’,’B’])) 2 solved JavaScript array to dictionary conversation based on count

[Solved] PHP Use array map to reOrder an array

You can simply use foreach instead like as foreach($your_arr as &$v){ $v = [$v[“period”] => $v[“way”]]; } print_r($your_arr); Or using array_map $your_arr = array_map(function($v){ return [$v[“period”] => $v[“way”]]; },$your_arr); print_r($your_arr); solved PHP Use array map to reOrder an array