开发者

What is the best way to add a single quote mark for an existing array key?

This is the code I used to get array key with single quote mark:

// the array with key and value
$savedFilesIds = array("F564574"=>"none","F456735"=>"none","F4777"=>"none")   

//$file_ids = imp开发者_如何学运维lode(',',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;

Is there other better way to make it more effective?


$quotedIds = array_map(create_function('$a', 'return "\'$a\'";'), array_keys($savedFilesIds));


foreach ($array as $k => $v)
{
    $array["'$k'"] = $v; 
    unset($array[$k]); 
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜