有一个类似这样的字符串
1,36,42,43,45,69,Standard,Executive,Premium我希望将其转换为数组,但只需要将数值转换为
Array
(
[0] => 1
[1] => 36
[2] => 42
[3] => 43
[4] => 45
[5] => 69
)数组中并非所有字符串值。
发布于 2016-06-23 14:47:25
使用array_filter、explode和is_numeric函数的简单而简短的解决方案:
$str = "1,36,42,43,45,69,Standard,Executive,Premium";
$numbers = array_filter(explode(",", $str), "is_numeric");
print_r($numbers);输出:
Array
(
[0] => 1
[1] => 36
[2] => 42
[3] => 43
[4] => 45
[5] => 69
)http://php.net/manual/en/function.is-numeric.php
https://stackoverflow.com/questions/37984089
复制相似问题