skulist的顺序和根据sale_props生成的笛卡尔积顺序不一致
需要一个函数修改正skulist顺序 让他和 sale_props生成的笛卡尔积顺序 一致
$json = '{"sale_props":[{"Id":"","Text":"颜色","Values":[{"Id":"","Text":"红色","pic":"https://static.leitool.com/shequntui/admin_up/103407_821521_12788.png","alias":"大红色"},{"Id":"","Text":"蓝色","pic":"https://static.leitool.com/shequntui/admin_up/103413_181761_36723.png","alias":"天蓝色"}]},{"Id":"","Text":"尺码","Values":[{"Id":"","Text":"X"},{"Id":"","Text":"M"}]}],"skulist":[{"id":"1619155904428830724","item_id":"1689932510544667110","sku_id":"1689906988110003683","attribute":"蓝色;M","props":"颜色:蓝色;尺码:M"},{"id":"1619155904428830727","item_id":"1689932510544667110","attribute":"红色;M","props":"颜色:红色;尺码:M"},{"id":"1619155904428830728","item_id":"1689932510544667110","sku_id":"1689906988110003660","attribute":"红色;X","props":"颜色:红色;尺码:X"},{"id":"1619155904428830726","item_id":"1689932510544667110","sku_id":"1689906988110003681","attribute":"蓝色;X","props":"颜色:蓝色;尺码:X"}]}';
$arr = json_decode($json, true);
$sale_props = $arr['sale_props'];
$skulist = $arr['skulist'];
$skulist = sortSkulist($sale_props, $skulist);
$arr['skulist'] = $skulist;
$json = json_encode($arr, JSON_UNESCAPED_UNICODE);
echo $json;
结果:
{
"sale_props": [
{
"Id": "",
"Text": "颜色",
"Values": [
{
"Id": "",
"Text": "红色",
"pic": "https://static.leitool.com/shequntui/admin_up/103407_821521_12788.png",
"alias": "大红色"
},
{
"Id": "",
"Text": "蓝色",
"pic": "https://static.leitool.com/shequntui/admin_up/103413_181761_36723.png",
"alias": "天蓝色"
}
]
},
{
"Id": "",
"Text": "尺码",
"Values": [
{
"Id": "",
"Text": "X"
},
{
"Id": "",
"Text": "M"
}
]
}
],
"skulist": [
{
"id": "1619155904428830728",
"item_id": "1689932510544667110",
"sku_id": "1689906988110003660",
"attribute": "红色;X",
"props": "颜色:红色;尺码:X"
},
{
"id": "1619155904428830727",
"item_id": "1689932510544667110",
"attribute": "红色;M",
"props": "颜色:红色;尺码:M"
},
{
"id": "1619155904428830726",
"item_id": "1689932510544667110",
"sku_id": "1689906988110003681",
"attribute": "蓝色;X",
"props": "颜色:蓝色;尺码:X"
},
{
"id": "1619155904428830724",
"item_id": "1689932510544667110",
"sku_id": "1689906988110003683",
"attribute": "蓝色;M",
"props": "颜色:蓝色;尺码:M"
}
]
}