我有一个包含这样数字的字符串:
$string = "694,852,94,94,743,202,127,127";
在PHP中从此字符串中获取整数数组的最佳和最快方法是什么?
Array ( [0] => 694,
[1] => 852,
[2] => 94,
[3] => 94,
[4] => 743,
[5] => 202,
[6] => 127,
[7] => 127 )
答案 0 :(得分:4)
$string = "694,852,94,94,743,202,127,127";
$array = explode(',',$string);
答案 1 :(得分:2)
$string = "694,852,94,94,743,202,127,127";
$array = explode(",", $string);
答案 2 :(得分:2)
试试这个
$string = "694,852,94,94,743,202,127,127";
$num = explode(",", $string);
$num
将包含从字符串中拆分的数字数组。
请参阅PHP Documentation。请先询问一次,然后再询问此处。
答案 3 :(得分:2)
$string = "694,852,94,94,743,202,127,127";
$arr = explode(",",$string);
如果您尝试在计算中使用数字,Php将自动进行类型转换。 How do I convert a string to a number in PHP?
答案 4 :(得分:1)
您应该使用explode
来构建您期望的数组:
$arr = explode(',',$string);
答案 5 :(得分:1)
您可以使用explode
使用分隔符将字符串转换为数组。例如
$array = explode(",", $string);
答案 6 :(得分:1)
<?php
$string = "694,852,94,94,743,202,127,127";
$arr = explode(",", $string);
答案 7 :(得分:1)
使用explode()
:
$string = "694,852,94,94,743,202,127,127";
$array = explode(",",$string);
答案 8 :(得分:0)
尝试explode()
喜欢
$string = "694,852,94,94,743,202,127,127";
$my_array = explode("," , $string);
print_r($my_array);
请参阅此explode