Converting arrray values to integer from request in laravel

3k views Asked by At

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

There are 1 answers

3
pr1nc3 On BEST ANSWER
$newArray = array_map('intval', $request->request->get('ids', []));

This code will convert your string fields to int so you can compare.