上面的代码,来本想着两个数组合并一下,用了array_push,结果总是多加了一层
后面换成了 array_merge 就可以了
贴上完整代码
$bodys = array();
foreach($item as $key => $value){
$item = array(
$value[0] => array(
'value' =>$value[1],
'color' =>$value[2]
)
);
$bodys = array_merge($bodys,$item);
}
$template = array(
"touser" => $openid,
"template_id" => $template_id,
'url' => $url,
'topcolor' => '#333',
'data' =>$bodys
);
$template = json_encode($template);