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

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

WBOY
Release: 2016-06-23 13:27:26
Original
1986 people have browsed it

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

$projectcode_array = ["20130719","20130718","20130717"];
Copy after login

通过

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'";
Copy after login

这样

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

 

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template