问题
I want to array_diff()
two arrays in Laravel. The first array looks like this:
array:4 [
0 => 7248
1 => 7249
2 => 7250
3 => 7251
]
the second one:
array:4 [
0 => "7248"
1 => "7249"
2 => "7250"
3 => "7251"
]
this one I get with $request->request->get('ids', []);
.
How can I convert one array to either strings or integers? As these arrays can grow large, I don't really want to convert every single value one at a time.
Update:
array_diff() is doing it's job, altough there are strings vs. integers.
Thanks in advance!
回答1:
$newArray = array_map('intval', $request->request->get('ids', []));
This code will convert your string fields to int so you can compare.
来源:https://stackoverflow.com/questions/54254409/converting-arrray-values-to-integer-from-request-in-laravel