数组遍历重组

 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

 

posted on 2021-03-06 09:49  kevin_yang123  阅读(89)  评论(0编辑  收藏  举报