【问题标题】:Laravel compare two arrayLaravel 比较两个数组
【发布时间】:2021-09-22 18:50:23
【问题描述】:

我必须数组,并且我必须从中找到差异值。 这是我的 Laravel 控制器代码

 $product_list = Operation::where('kvit_id', $kvit->id)->pluck('product_id')->toArray();
 $hamkor_products = ListProduct::where('user_id', $newkvit->user_id)->pluck('product_id')->toArray();
 $operProductList =  array_diff($product_list, $hamkor_products);
 dd($product_list, $hamkor_products, $operProductList);

这是我得到的结果

我犯了什么错误? $operProductList 是返回 []

【问题讨论】:

    标签: arrays laravel array-difference


    【解决方案1】:

    你必须改变array_diff()中的参数顺序,它必须是这样的:

    $product_list = Operation::where('kvit_id', $kvit->id)->pluck('product_id')->toArray();
     $hamkor_products = ListProduct::where('user_id', $newkvit->user_id)->pluck('product_id')->toArray();
     $operProductList =  array_diff($hamkor_products, $product_list);
     dd($product_list, $hamkor_products, $operProductList);
    

    【讨论】:

      猜你喜欢
      • 2019-02-20
      • 2020-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-11
      • 2012-12-26
      • 2021-03-21
      • 1970-01-01
      相关资源
      最近更新 更多