Home >Backend Development >PHP Tutorial >把PHP的数组变成带单引号的字符串

把PHP的数组变成带单引号的字符串

WBOY
WBOYOriginal
2016-06-23 13:27:261992browse

上次做项目的时候,遇到 查询结果为 数组。因为条件原因,需要用
$where['_string'] 去组合查询。进而用到把数组变成单引号的字符串。
举例:
查询返回的数组为:

$projectcode_array = ["20130719","20130718","20130717"];

通过

function change_to_quotes($str) {    return sprintf("'%s'", $str); }$new_projectcode_array =  implode(',', array_map('change_to_quotes', $projectcode_array ));$new_projectcode_array="'20130719','20130718','20130717'";

这样

$where['_string']="abc in ($new_projectcode_array)";

 

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn