我正在尝试转换这些整数/数字:
$groups = '1707,1723,1733,16254,16256,18704,19792,29268,34956';
进入PHP数组中的数组:
array("1707","1723","1733","29268","34956");
我正在使用这个
$tags = array();
foreach($groups as $index){
array_push($tags, $index);
}
但是继续得到以下错误。
Error: Invalid argument supplied for foreach()
答案 0 :(得分:2)
简单explode致电:
$array=explode(',',$groups);
答案 1 :(得分:1)
explode()函数将字符串分解为数组。
$groups = '1707,1723,1733,16254,16256,18704,19792,29268,34956';
print_r(explode(",",$groups));