使用array_diff()后,只获取Laravel Php中数组的原始值

I am using arra_diff() to remove any matching element. but the returned results contains key and values. I am only interested in the values and not the keys.

below is the output:

array 1:
[5,7,11,14,15,22,23,24]

array 2:
[19,7]

Result (I dont like this):
{"0":5,"2":11,"3":14,"4":15,"5":22,"6":23,"7":24}

I need:
[5,11,14,15,22,23,24]

mycode

$array_1 = query->get()->pluck('id')->toArray();
$array_2 = query->get()->pluck('id')->toArray();
$result  = array_diff($array_1, $array_2);
return $result

You can use array_values to get it. Try this,

array_values($result);

Every laravel query returns in result a Laravel Collection.

As Documentation of laravel say, you have a diff method that will help.

The diff method compares the collection against another collection or a plain PHP array based on its values. This method will return the values in the original collection that are not present in the given collection.

So in your case you need just to do:

$array_1 = $query->get()->pluck('id');
$array_2 = $query->get()->pluck('id');
$result  = $array_2->diff($array_1);
return $result->values();

in result we will use another method values to get just values of collection...