Home > Backend Development > PHP Problem > How to convert numbers into array in php

How to convert numbers into array in php

藏色散人
Release: 2023-03-12 20:16:01
Original
2936 people have browsed it

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

How to convert numbers into array in php

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="";
        }
    }
}
Copy after login

Print data:

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

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!

Related labels:
php
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template