php - 使用 PHP 如何将数组转换为用于 SQL 查询的项目字符串
问题描述
我需要使用循环获取我在数组中获取的大量数组,即
$uuids = [];
foreach($data AS $item) {
$uuids[] = $item->uuid;
}
$uuids = implode(",", $uuids);
但是在这种方法中,我要返回
"123-asdf,122-asfdsa,2323-aewrq"
但是我需要
'123-asdf','122-asfdsa','2323-aewrq'
如果我将上述作为字符串连接进行,即
$uuids = "";
foreach($data AS $item) {
$uuids .= "'$item->uuid',";
}
$uuids = implode(",", $uuids);
我明白了
'\'123-asdf\',\'122-asfdsa\',\'2323-aewrq\'
我又不能将其用于 SQL where 语句。请问有人有什么建议可以帮忙吗?
解决方案
推荐阅读
- python - 在 Pandas 中使用窗口进行动态异常值检测
- javascript - 使用 moment.js 创建过去 24 小时的数组
- ios - Alamofire ObjectMapper - 从所有模型中提取公共字段并映射它们
- neo4j - Neo4j APOC 删除触发器
- javascript - 将 ngFor 循环的最后一个元素滚动到视图中
- ios-charts - 分组水平条形图 - 不使用组空间的组标签
- java - 引起:javax.persistence.TransactionRequiredException:在带有 Spring JTA Transaction 的 Weblogic 上
- java - Eclipse,如何递归查找类依赖项
- vue.js - 如何使用 vuex 在对象中保持 aa 属性的状态
- c# - 纹理数组仅获取最后一个索引(C# UNITY)