码迷,mamicode.com
首页 > 编程语言 > 详细

PHP 将字符串中的数字转化为数组

时间:2019-11-18 18:26:13      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:article   数组   size   字符   sdn   pre   http   tps   str   

$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="";
}
}
}


打印数据:

  Array
  (
    [0] => 2019
    [1] => 11
    [2] => 18
    [3] => 17
    [4] => 25
  )

 

 

参考链接:https://blog.csdn.net/jiangnanqbey/article/details/81354968 

 

 

 

PHP 将字符串中的数字转化为数组

标签:article   数组   size   字符   sdn   pre   http   tps   str   

原文地址:https://www.cnblogs.com/caia-agul/p/11883554.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!