Home >Backend Development >PHP Problem >How to convert numbers into array in php
php method to convert numbers into arrays: 1. Create a PHP sample file; 2. Define a string containing numbers; 3. Pass "for($i=0;$i
The operating environment of this article: Windows 7 system, PHP version 7.1, Dell G3 computer.
How to convert numbers into arrays in php?
PHP Convert the numbers in the string into an array
$str ='现在是2019年11月18日下午17点25分'; $result=''; $arr=[]; for($i=0;$i<strlen($str);$i++){ if(is_numeric($str[$i])){ $result.=$str[$i]; }else{ if($result!="") { $arr[] = $result; $result=""; } } }
Print data:
Array ( [0] => 2019 [1] => 11 [2] => 18 [3] => 17 [4] => 25 )
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to convert numbers into array in php. For more information, please follow other related articles on the PHP Chinese website!