文字列に単独で発生するすべての数値を格納することを検討しています。整数は単独で発生し、空白で囲まなければなりません。文字列から数値を保存する
ここで私が何を意味するかです:
入力
何とか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- numbers-in-stringではなく、リンクを参照のままにしておきます。 – mickmackusa