其他分享
首页 > 其他分享> > 数组遍历重组

数组遍历重组

作者:互联网

 1.array_map() 函数将用户自定义函数作用到数组中的每个值上,可以获取到多个数值相同的数值
$info = array_map(function ($row) use ($param0) {
                    $tmpRow['ali_cate_id'] = $row['id'];
                    $tmpRow['ali_cate_parent_id'] = $param0;
                    $tmpRow['level'] = $row['level'];
                    $tmpRow['created_at'] = date('Y-m-d H:i:s');
                    $names = json_decode($row['names'], true);
                    $tmpRow['zh_name'] = isset($names['zh']) ? $names['zh'] : '';
                    $tmpRow['en_name'] = isset($names['en']) ? $names['en'] : '';
                    $tmpRow['isleaf'] = (int)$row['isleaf'];
                    return $tmpRow;
                }, $result['result']['aeop_post_category_list']['aeop_post_category_dto']);

2.遍历foreach 方法
foreach ($listingAttrItemImg as $k =>$v){
$listingAttrItemImgs[] =['listing_id'=>$new_id,
'sku'=>$v['sku'],
'attr_item_id'=> $v['attr_item_id'],
'img_path' => $v['img_path'],
'amazon_path' => !empty($v['amazon_path'])?$v['amazon_path']:'1',
'image_state' => $v['image_state'],
'type' => $v['type'],
'attr_item_id'=> $v['attr_item_id'],
'created_at'=>date('Y-m-d H:i:s'),
'updated_at'=>date('Y-m-d H:i:s'),
];
}
//拼凑成新的数值 根据同一id

 

标签:重组,遍历,attr,tmpRow,names,数组,path,id,row
来源: https://www.cnblogs.com/kevin-yang123/p/14489603.html