从数组列创建逗号分隔的字符串[重复]

问题描述 投票:0回答:2

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");

我需要

$color = "gold,silver,purple";
php arrays multidimensional-array delimited
2个回答
0
投票

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


0
投票

根据您更新的问题:

你可以尝试这样的事情:

'名字_值','姓氏'=>'姓氏_值'); sprintf('插入 %s (%s) 值 ("%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") ?>
© www.soinside.com 2019 - 2024. All rights reserved.