Evaluate the foreach output array to determine the output code. some of the output code has been completed with arrays.
Array ([0] => stdClass Object ([CounterCode] => 0002 [Countername] => South floor [BuildDate] => 20130101 [xsje] => 97600) [1] => stdClass Object ([CounterCode] => 0002 [Countername] => South floor [BuildDate] => 20130102 [xsje] => 84808) [2] => stdClass Object ([CounterCode] => 0002 [Countername] => South floor [BuildDate] => 20130103 [xsje] => 112221.8) [3] = & gt; stdClass Object ([CounterCode] = & gt; 0002 [Counternam E] => [BuildDate] => 20130104 [xsje] => 100316) [4] => stdClass Object ([CounterCode] => 0002 [Countername] => South floor [BuildDate] => 20130105 [xsje] => 48966) [5] => stdClass Object ([CounterCode] => 0003 [Countername] => South Building 2 [BuildDate] => 20130101 [xsje] => 54862) [6] => stdClass Object ([CounterCode] => 0003 [Countername] => South Building 2 [BuildDate] => 20130102 [xsje] => 61934) [7] => stdcia Ss Object ([CounterCode] => 0003 [Countername] => South building second floor [BuildDate] => 20130103 [xsje] => 47470) [8] => stdClass Object ([CounterCode] => 0003 [Countername] => South Building 2 [BuildDate] => 20130104 [xsje] => 39975) [9] => stdClass Object ([CounterCode] => 0003 [Countername] => South Building 2 [BuildDate] => 20130105 [xsje] => 30111 )... N
Ps: [CounterCode] = & gt; 0003 (string)
[Countername] => second floor, South Building (string)
[BuildDate] = & gt; 20130105 (date)
[Xsje] => 30111 (amount)
The format to be output is (meaning: CounterCode = 0002 sales amount is output by day)
CounterCode: '0002',data: [97600,84808,112221.8,100316,48966]},CounterCode: '0003',data: [54862,61934,47470,39975,30111]},
Now I can output
{name:'0002',data:[]},{name:'0003',data:[]},{name:'0004',data:[]},{name:'0005',data:[]},{name:'0006',data:[]},{name:'0008',data:[]},{name:'0009',data:[]}
Code
CounterCode. "',"; echo "data: ["; find this part of code echo "]}" ;}?>
Delete the last punctuation mark
Reply to discussion (solution)
$tmpxsje = [];foreach($users as $user){$tmpxsje[$user->CounterCode][] = $user->xsje;}$data = [];foreach($tmpxsje as $k=>$v){$tmp['name'] = $k;$tmp['data'] = $v;$data[] = $tmp;}echo json_encode($data);//[{"name":"0002","data":[97600,84808,112221.8,100316,48966]},{"name":"0003","data":[54862,61934,47470,39975,30111]}]
Thank you, jam00.
I just did not pay attention to it. isn't it the format I requested?
CounterCode: '20180101', data: [97600,84808, 0002, 112221.8, 48966]},
CounterCode: '000000', data: [54862,61934, 47470,39975, 0003]},
I want something like this.
Foreach ($ tmpxsje as $ k => $ v ){
$ Tmp ['countercode'] = $ k;
$ Tmp ['data'] = $ v;
$ Data [] = $ tmp;
}