2013-07-03 101 views
-7

我有一個數字的字符串是這樣的:PHP:從字符串的數字數組

$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

http://in3.php.net/manual/en/ function.explode.php –

+4

Absoulutel沒有研究完成。至少在谷歌上查找它。 – user568109

+1

@HamZa如果他/她不知道爆炸怎麼辦? 當搜索php的「拆分」等價物時,爆炸不會自動彈出,如果您習慣於其他語言,則從字符串到int的類型轉換並不十分明顯。所以你的評論有點粗魯。 – Tschallacka

回答

2
$string = "694,852,94,94,743,202,127,127"; 
$array = explode(",", $string); 
2

嘗試此

$string = "694,852,94,94,743,202,127,127"; 

$num = explode(",", $string); 

$num將包含來自串數分割的陣列。

請參閱PHP Documentation。並請在此詢問Google之前一次。

1

如果要在使用explode數組你期望:

$arr = explode(',',$string); 
1

可以使用explode字符串轉換爲使用分隔符的數組。

例如

$array = explode(",", $string); 
1
<?php 
    $string = "694,852,94,94,743,202,127,127"; 
    $arr = explode(",", $string); 
1

使用explode()

$string = "694,852,94,94,743,202,127,127"; 

$array = explode(",",$string); 
0

嘗試用explode()

$string = "694,852,94,94,743,202,127,127"; 
$my_array = explode("," , $string); 
print_r($my_array); 

請參閱本explode