我有以下列表,我以这种格式从Android获得PHP:
//How I get phonenumberlist
$phonenumberlist = isset($_POST['PhoneNumberList']) ? $_POST['PhoneNumberList'] : '';
//The output of phonenumberlist when I print to text
$phonenumberlist = [0761234567, 072999999, 0731111111];
我想单独爆炸这些数字,我试过:
$phonenumberlist_exploded = explode(',', $phonenumberlist);
foreach ($phonenumberlist_exploded as $number)
{
echo $number;
}
我收到以下警告:
Warning: explode() expects parameter 2 to be string, array given in
答案 0 :(得分:1)
$phonenumberlist
已经是一个数组。没有必要爆炸它。只需迭代它就可以回显出值。
You will have an issue with the leading zeros:
解析错误:无效的数字文字
因此,您需要将这些值包装在引号中,以使PHP将它们作为字符串处理:
$phonenumberlist = ['0761234567', '072999999', '0731111111'];
foreach($phonenumberlist as $number) {
echo $number;
}
答案 1 :(得分:1)
您可以像这样转换列表: -
$phonenumberlist = '[0761234567, 072999999, 0731111111]';
$phonenumberlist = str_replace([' ', '[', ']', ','], ['', '["', '"]', '","'], $phonenumberlist);
$phonenumberlist = json_decode($phonenumberlist, true);
它会: -
[编辑1] 另一种选择: -
$phonenumberlist = '[0761234567, 072999999, 0731111111]';
$phonenumberlist = trim(trim($phonenumberlist, '['), ']');
$phonenumberlist = explode(', ', $phonenumberlist);
希望这有帮助。