这是我用来获取带有单引号的数组键的代码:
// the array with key and value
$savedFilesIds = array("F564574"=>"none","F456735"=>"none","F4777"=>"none")
//$file_ids = implode(',',array_keys($savedFilesIds)); // without adding single quote mark for keys
// the way I used to adding single quote mark for keys
$file_ids = array();
foreach($savedFilesIds as $key=>$value){
$item = '\''.$key.'\''; // adding single quote mark here
array_push($file_ids , $item); // and then adding to array
}
$file_ids = implode(',',$file_ids); // get the key with single quote mark
echo $file_ids;
还有其他更好的方法可以让它更有效吗?
答案 0 :(得分:4)
$quotedIds = array_map(create_function('$a', 'return "\'$a\'";'), array_keys($savedFilesIds));
答案 1 :(得分:0)
foreach ($array as $k => $v)
{
$array["'$k'"] = $v;
unset($array[$k]);
}