相关疑难解决方法(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万
查看次数

字符串到整数php的数组

我想将一个字符串(例如1,2,3,4,5,6)转换为php中的整数数组?我找到的函数只能访问字符串的第一个字符,例如1.如何将整个字符串转换为数组?

function read_id_txt()
{

        $handle_file = fopen("temporalfile.txt", 'r'); 

        $i=0;

        while ($array_var[$i] = fgets($handle_file, 4096)) { 
            echo "<br>";
            print_r($array_var[i]);
            $i++;
        }

        fclose($handle_file);   

        $temp=explode(" ", $array_var[0]);      

        return $temp;   


}
Run Code Online (Sandbox Code Playgroud)

php arrays string integer

7
推荐指数
2
解决办法
2万
查看次数

标签 统计

php ×2

string ×2

arrays ×1

explode ×1

int ×1

integer ×1