如何在PHP中分割以逗号分隔的数组关键字值?
我在 $_POST 中有一个数组:
Array ( [tags] => Javascript,PHP,Java,C++,Python)
如何将此数组转换为这样的数组:
Array ( [tag1] => Javascript [tag2] => PHP [tag3] => Java [tag4] => C++ [tag5] => Python)
我想我需要使用正则表达式来删除逗号并在“foreach as”中进行分割..但我是 PHP 新手.. 。 请帮我
I have an array in $_POST:
Array ( [tags] => Javascript,PHP,Java,C++,Python)
How can i convert this Array into Array like this:
Array ( [tag1] => Javascript [tag2] => PHP [tag3] => Java [tag4] => C++ [tag5] => Python)
I guess i need to use regexp to remove the commas and do split in "foreach as".. But i'm so newbie in PHP... Please help me
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
输出
Outputs
对于带逗号的字符串,可以使用explode进行拆分
$new_array =explode(',', $_POST['tags']);
然后就可以使用
$new_array
适合您的流程。For a string with comma, you can split it using explode
$new_array = explode(',', $_POST['tags']);
Then you can use the
$new_array
for your process.