php对象数组转换为json格式数组,再转回object对象数组

来源:互联网 发布:hive sql union all 编辑:程序博客网 时间:2024/06/05 18:14
$list为数据库获取的对象数组,
$json_encode($obj0) 对$obj0进行json编码
$arr=json_decode( json_encode($obj0), true ); 转换为数组
$list[$i]=$arr= (object) $arr;//数组转换会object


for($i=0;$i<count($list);$i++){
$obj0=$list[$i];//拿到最大的object
$arr=json_decode( json_encode($obj0), true );//转换object为数组
if
($arr['P_discount']==10){
$arr['P_discount']='-';//数组下标重新赋值 };
if($arr['P_paytime']!=0){ //数组下标重新赋值
$arr['P_paytime']=date('Y-m-d', $arr['P_paytime']); }
$list[$i]=$arr= (object) $arr;//数组转换会object}
原创粉丝点击