这里我试图在foreach循环得到的值中添加一个逗号.现在这些值都在一起,但是我希望它以逗号分隔的方式回显.请建议我,我要做什么.我知道,我必须使用内爆,但我不知道如何在循环中完成它.
foreach($_POST['insert'] as $interested) {
if(!preg_match('/^[-A-Z0-9\., ]+$/iD', $interested)) continue;
echo $interested;
}
Run Code Online (Sandbox Code Playgroud)
如果你想保持你的代码相对不受影响(虽然我修复了令人困惑的缩进)...
$interestedValues = array();
foreach($_POST['insert'] as $interested) {
if(!preg_match('/^[-A-Z0-9\., ]+$/iD', $interested)) continue;
$interestedValues[] = $interested;
}
echo implode(',', $interestedValues);
Run Code Online (Sandbox Code Playgroud)
......或者因为一个衬里看起来很时髦......
echo implode(',', preg_grep('/^[-A-Z\d., ]+$/iD', $_POST['insert']));
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1504 次 |
最近记录: |