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

$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}

猜你喜欢

转载自blog.csdn.net/cand6oy/article/details/77921902