我有一个这样的数组结果Array( [e] => 6 [i] => 5 [s] => 4 [n] => 0 [t] => 0)我需要将数组格式更改为此,Array( [0] => stdClass Object ( [type] => e [count] => 6 ) [1] => stdClass Object ( [type] => i [count] => 5 ) [2] => stdClass Object ( [type] => s [count] => 4 ) [3] => stdClass Object ( [type] => n [count] => 0 ) [4] => stdClass Object ( [type] => t [count] => 0 ))有什么办法可以改变吗?
1 回答
郎朗坤
TA贡献1921条经验 获得超9个赞
$newArray = [];
foreach ($array as $k => $v) {
$obj = new stdClass;
$obj->type = $k;
$obj->count = $v;
$newArray[] = $obj;
}
- 1 回答
- 0 关注
- 117 浏览
添加回答
举报
0/150
提交
取消