从PHP数组中获取逗号分隔值

时间:2012-02-27 11:23:36

标签: arrays multidimensional-array

我们在PHP中有任何数组函数来实现这个目的:

// get all the user ids as comma seprated.
        $users = array();
        foreach($view as $result)
        {       
            $users[] = $result->uid;            
        }
        $uid = implode(',', $users);

示例:

$array[0] = array("size" => "XL", "color" => "gold");
$array[1] = array("size" => "XLL", "color" => "siver");
$array[2] = array("size" => "M", "color" => "purple");

I need 
$color = "gold,silver,purple";

先谢谢你的帮助。

2 个答案:

答案 0 :(得分:0)

您可以使用explode(',',$ view)来获取值数组。

答案 1 :(得分:0)

从您更新的问题:

您可以尝试这样的事情:

'firstname_value', '姓氏'=> 'lastname_value'); sprintf('INSERT INTO%s(%s)VALUES(“%s”)','table_name',implode(',',array_map('mysql_escape_string',array_keys($ values))),implode('“,” ',array_map('mysql_escape_string',$ values))); //它给你:INSERT INTO table_name(firstname,lastname)VALUES(“firstname_value”,“lastname_value”) ?>