如何整数转换为PHP中的数组? [英] How to convert an integer to an array in PHP?
本文介绍了如何整数转换为PHP中的数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
什么是一个整数转换为数字数组?
What would be the most simple way to convert an integer to an array of numbers?
例如:
2468
应导致阵列(2,4,6,8)
。
推荐答案
You can use str_split
and intval
:
$number = 2468;
$array = array_map('intval', str_split($number));
var_dump($array);
这将给输出如下:
Which will give the following output:
array(4) {
[0] => int(2)
[1] => int(4)
[2] => int(6)
[3] => int(8)
}
这篇关于如何整数转换为PHP中的数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文