相关疑难解决方法(0)

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

$string = "1,2,3"
$ids = explode(',', $string);
var_dump($ids);
Run Code Online (Sandbox Code Playgroud)

回报

array(3) {
  [0]=>
  string(1) "1"
  [1]=>
  string(1) "2"
  [2]=>
  string(1) "3"
}
Run Code Online (Sandbox Code Playgroud)

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

php string int explode

219
推荐指数
10
解决办法
20万
查看次数

标签 统计

explode ×1

int ×1

php ×1

string ×1