Hayrulla Melibayev
Hayrulla Melibayev

Reputation: 532

Get second flat array's values not found in first flat array

I have to arrays and I have to find difference values from it. Here is my Laravel Controller code

 $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);

Here is result which I'm getting

enter image description here

What kind of mistake I made? $operProductList is returns []

Upvotes: 0

Views: 425

Answers (1)

Rateb Habbab
Rateb Habbab

Reputation: 1789

You must just change the order of parameters in array_diff(), it must be like :

$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);

Upvotes: 1

Related Questions