如何将数组值从字符串转换为int?

如何将数组值从字符串转换为int?

问题描述:

$string = "1,2,3"
$ids = explode(',', $string);
var_dump($ids);

返回

array(3) {
  [0]=>
  string(1) "1"
  [1]=>
  string(1) "2"
  [2]=>
  string(1) "3"
}

我需要价值观是int类型而不是string类型。有没有比使用foreach循环数组并将每个字符串转换为int更好的方法呢?

I need for the values to be of type int instead of type string. Is there a better way of doing this than looping through the array with a foreach and converting each string to int?

$integerIDs = array_map('intval', explode(',', $string));