我正在寻找将单独出现在字符串中的所有数字都存储起来。整数必须单独出现并被空白空间包围。从字符串中保存数字
这里就是我的意思是:
输入
等等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