Arrays 如何比较两个数组集合并在不同的选项卡中显示?

Arrays 如何比较两个数组集合并在不同的选项卡中显示?,arrays,laravel,collections,Arrays,Laravel,Collections,这是我的收集结果 //database data Collection {#1526 ▼ #items: array:2 [▼ 0 => array:14 [▼ "item_code" => "Albatrs001" "product_name" => "CHILLED SALMON WHOLE (CTNx2NOS/4-5KG FILLETS & Trimmings3KG) " "description" =>

这是我的收集结果

//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"
    ]
  ]
}
我想比较这两个集合,并在选项卡中显示新记录和更改。我有两个选项卡来显示新的和记录的更改。我将只显示做出更改的新的和记录

我正在使用嵌套循环来比较和突出显示更改,但是是否有任何方法可以只显示进行更改的new和record,并将它们分配给不同的选项卡

// want to compare
$reader = \Excel::load(Input::file('import_file'))->toArray(); 
$result = DB::table('items')->select('....')->get();

基于给定阵列的工作解决方案:

$db = array_map('serialize', $db);
$excel = array_map('serialize', $excel);
$diff = array_map('unserialize', array_diff($excel, $db));

因此,需要序列化数组。您将获得一个字符串数组(序列化数组)。然后使用
array\u diff
比较这些字符串。然后,您只需取消序列化结果。最后,您得到了一个数组。

您尝试过diff()吗?我得到一个错误“调用数组上的成员函数diffAssoc()”@Crazy,你说过这是一个集合。如果获得一个集合,然后将其转换为数组,请删除
toArray()
部分。如果它从一开始就是一个数组,请尝试使用
collect($array)
将其包装到集合中,或者改用。是的,其中之一是作为数组$reader=\Excel::load(Input::file('import_file'))->toArray(),我尝试了您的方法,但它返回给我无法转换为stdClass类的对象string@Crazy如果有办法让你分享一件原始收藏的作品,请这样做。然后我就可以给你一个有效的解决方案了。$reader=\Excel::load(输入::文件('import_文件'))->toArray()$result=DB::table('items')->select('....')->get();我想比较$result和$reader。