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

How to convert integer to array in php

藏色散人
藏色散人Original
2021-06-10 09:20:251779browse

php method to convert integers to arrays: First create a PHP sample file; then use the "array_map('intval', str_split($number));" method to convert integers into arrays.

How to convert integer to array in php

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

How does php convert an integer to an array?

You can use str_split and intval:

$number = 2468;
    $array  = array_map('intval', str_split($number));
var_dump($array);

This will give the following output:

array(4) {
  [0] => int(2)
  [1] => int(4)
  [2] => int(6)
  [3] => int(8)
}

[Recommended learning: PHP video tutorial]

The above is the detailed content of How to convert integer to array in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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