如何在PHP中分割以逗号分隔的array关键字值? [英] How to split the array keyword value separated by commas in PHP?

查看:103
本文介绍了如何在PHP中分割以逗号分隔的array关键字值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在$ _POST中有一个数组:

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)

我想我需要使用正则表达式删除逗号并在"foreach as"中拆分..但是我在PHP中是如此新手...请帮助我

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

推荐答案

$tags = explode(",", $_POST['tags']);
print_r($tags);

输出


Array (
  [0] => Javascript
  [1] => PHP
  [2] => Java
  [3] => C++
  [4] => Python
)

这篇关于如何在PHP中分割以逗号分隔的array关键字值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆