我有一个字符串变量作为
$p_list="1,2,3,4";
我想把它转换成像这样的数组
$a[0]='1';
$a[1]='2';
$a[2]='3';
$a[3]='4';
如何在php中做到这一点?
使用爆炸。
$p_list = "1,2,3,4";
$array = explode(',', $p_list);
请参阅代码板。
尝试爆炸$a=explode(",","1,2,3,4");
试试这个:
In PHP, explode function will convert string to array, If string has certain pattern.
<?php
$p_list = "1,2,3,4";
$noArr = explode(",", $p_list);
var_dump($noArr);
?>
You will get array with values stores in it.
- 谢谢