这是我的收藏结果
//database data
Collection {#1526 ▼
#items: array:2 [▼
0 => array:14 [▼
"item_code" => "Albatrs001"
"product_name" => "CHILLED SALMON WHOLE (CTNx2NOS/4-5KG FILLETS & Trimmings3KG) "
"description" => "abc"
"category" => "Seafood"
"input_tax" => "ZP"
"output_tax" => "ZRL"
"sla" => 5.0
"threshold_day" => 5.0
"threshold_max_qty" => 0.0
"order_limit" => 9.0
"reference_qty" => null
"reference_expiry_date" => "5"
"default_unit_price" => 48.0
"default_uom" => "KG"
]
1 => array:14 [▼
"item_code" => "Albatrs002"
"product_name" => "SMOKED SALMON WHOLE /PKT "
"description" => "cdf"
"category" => "Seafood"
"input_tax" => "TX"
"output_tax" => "SR"
"sla" => 5.0
"threshold_day" => 5.0
"threshold_max_qty" => 0.0
"order_limit" => 4.0
"reference_qty" => null
"reference_expiry_date" => "5"
"default_unit_price" => 80.0
"default_uom" => "PKT"
]
]
}
//excel data
Collection {#1526 ▼
#items: array:3 [▼
0 => array:14 [▼
"item_code" => "Albatrs001"
"product_name" => "CHILLED SALMON WHOLE (CTNx2NOS/4-5KG FILLETS & Trimmings3KG) "
"description" => "abc"
"category" => "Seafood"
"input_tax" => "ZP"
"output_tax" => "ZRL"
"sla" => 5.0
"threshold_day" => 5.0
"threshold_max_qty" => 0.0
"order_limit" => 9.0
"reference_qty" => null
"reference_expiry_date" => "5"
"default_unit_price" => 48.0
"default_uom" => "KG"
]
1 => array:14 [▼
"item_code" => "Albatrs002"
"product_name" => "SMOKED SALMON WHOLE /BAG "
"description" => "ggg"
"category" => "Seafood"
"input_tax" => "TX"
"output_tax" => "SR"
"sla" => 5.0
"threshold_day" => 5.0
"threshold_max_qty" => 0.0
"order_limit" => 4.0
"reference_qty" => null
"reference_expiry_date" => "5"
"default_unit_price" => 80.0
"default_uom" => "PKT"
]
2 => array:14 [▼
"item_code" => "Albatrs003"
"product_name" => "ABCDEFG "
"description" => "cccc"
"category" => "dddd"
"input_tax" => "TX"
"output_tax" => "SR"
"sla" => 5.0
"threshold_day" => 5.0
"threshold_max_qty" => 0.0
"order_limit" => 4.0
"reference_qty" => null
"reference_expiry_date" => "5"
"default_unit_price" => 80.0
"default_uom" => "PKT"
]
]
}
我想比较两个集合并在标签中显示新记录和更改。我有两个标签显示新的和更改记录。我只会展示新的和记录的变化。
我使用嵌套循环来比较和突出显示更改,但有没有方法只显示更改并将其分配给不同选项卡的新记录和记录?
// want to compare
$reader = \Excel::load(Input::file('import_file'))->toArray();
$result = DB::table('items')->select('....')->get();
答案 0 :(得分:2)
基于给定数组的工作解决方案:
$db = array_map('serialize', $db);
$excel = array_map('serialize', $excel);
$diff = array_map('unserialize', array_diff($excel, $db));
因此,您序列化数组。你得到一个字符串数组(序列化数组)。然后使用array_diff
比较这些字符串。然后你只是反序列化结果。最后,你得到一个阵列。