简体   繁体   中英

Converting arrray values to integer from request in laravel

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!

$newArray = array_map('intval', $request->request->get('ids', []));

此代码会将您的字符串字段转换为int,以便您进行比较。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM