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

How to convert integer to array in php

藏色散人
Release: 2023-03-08 17:40:01
Original
2364 people have browsed it

php method of converting integers to arrays: first create a PHP sample file; then define an integer; then convert the integer into a numeric array through "array_map('intval', str_split($number));" Can.

How to convert integer to array in php

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

The simplest way to convert an integer into a digital array is What?

Example:

2468 should produce array (2,4,6,8).

You can use str_split and intval:

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

This will The following output is given:

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

[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!

Related labels:
php
source:php.cn
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