$con = '2010年工资¥2000,2011年工资¥3000,2012年工资¥4000,2013年工资¥4500,2014年工资¥5000,2015年工资¥5000,2016年工资¥5500,2017年工资¥5500,2018年工资¥6000,2019年工资¥6500';
我现在需要把$con弄成数组,遍历插入数据库
insert info table_name (nian, gongzi) VALUES ($nian, $gongzi)
最终的数据库结果
id nian gongzi
1 2010 2000
2 2011 3000
3 2012 4000
4 2013 4500
5 2014 5000
............
请问这个过程PHP数组怎么处理?
<?php
header("Content-type: text/html; charset=utf-8");
$con = '2010年工资¥2000,2011年工资¥3000,2012年工资¥4000,2013年工资¥4500,2014年工资¥5000,2015年工资¥5000,2016年工资¥5500,2017年工资¥5500,2018年工资¥6000,2019年工资¥6500';
$info=array();
$data=explode(",",$con);
echo "<pre>";
print_R($data);
foreach ($data as $k=>$v){
$info[$k]['nian']=explode("年",$v)[0];
$info[$k]['gongzi']=explode(";",$v)[1];
}
print_R($info);
?>
先把结果存数组里 然后
echo json_encode($arr);
转为json后 用js就好处理了