开发者

How to split the array keyword value separated by commas in 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


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

Outputs

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜