在php中将字符串组合成一个数组

I have a web service to identify people and their functions from an external database that returns me a set of data if the login is successful. The data (that interests me right now) is separated in different strings as follow:

$groups="group1, group2, group3"
$functions="member, member, admin"

The first element of the string $groups corresponds to the first element of the $functions string.

We can have empty spots in the strings:

$groups="group1,, group3";
$functions="member,, admin";

What is the best way to combine them to obtain:

$usertype(
    group1=>member, 
    group2=>member, 
    group3=>admin,
);

Then I plan to use array_search() to get the name of the group that corresponds to a function.

查看全部
douya1061
douya1061
2013/06/11 12:13
  • string
  • php
  • arrays
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

7个回复