我正在尋找將單獨出現在字符串中的所有數字都存儲起來。整數必須單獨出現並被空白空間包圍。從字符串中保存數字
這裏就是我的意思是:
輸入
等等5等等bl3h 555等等123等等A2B3 5030a
期望輸出
[5 ],[55 5],[123]
這裏是我的嘗試迭代,似乎當前的單詞正確組但卻不會添加到陣列
//$a = String
function numberReturn($a){
$currWord;
$numberArray = array();
//Loop through string
for($i = 0; $i < strlen($a); $i++){
//Keep adding chars to current word
$currWord .= $a[$i];
//if white space check if current word is only numeric
//if only numbers add it to array
//when added, clear current word
if(ctype_space($a[$i])){
if(is_numeric($currWord)){
$numberArray[] = $currWord;
}
$currWord = "";
}
}
return $numberArray;
}
我很想進行投票頁面爲重複的:https://stackoverflow.com/questions/9452234/php-how-to-find-字符串中的數字,但我只是將該鏈接作爲參考。 – mickmackusa