我有简单的数组:
$array = array(1,5,7,9,3,0);
并从数据库中收集:
$collection = DB::table('numbers')->pluck('number');
Collection {#194 ▼
#items: array:12 [▼
0 => "1"
1 => "2"
2 => "3"
3 => "4"
4 => "5"
5 => "6"
]
}
我怎样才能在Laravel中比较这个数组?以及如何在laravel中将默认数组($ array)与另一个数组进行比较:
$another_array = DB::select("SELECT number FROM numbers");
array:12 [▼
0 => {#194 ▼
+"number": "0"
}
1 => {#207 ▼
+"number": "-1"
}
2 => {#209 ▼
+"number": "1"
}
3 => {#206 ▼
+"number": "-2"
}
]
尝试:
$collection = DB::table('numbers')->pluck('number')->toArray();
$diff = array_diff($collection, $array);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句