php把接收的参数循环输出拼接成mysql查询条件语句
2024-05-10 Umming PHP学习 评论(0) 浏览(602)
<?php function buildSqlCondition($params) { $condition = ""; foreach ($params as $key => $value) { if (is_array($value)) { foreach ($value as $item) { $condition.= " $key = '$item' OR"; } } else { $condition.= " $key = '$value' AND"; } } // 去掉最后多余的 "OR" 或 "AND" $condition = rtrim($condition, " OR"); $condition = rtrim($condition, " AND"); return $condition; } // 示例用法 $parameters = [ 'special' => ["FRD", "G3"], 'vthMax' => ["3.9", "4.5"], 'vthMin' => ["2.0", "2.9", "3.0"] ]; echo buildSqlCondition($parameters); ?>
标签: php
本文链接:https://www.umming.com/php/325.html 百度已收录
声明:本站信息由网友自行发布或来源于网络,真实性、合法性由发布人负责,请仔细甄别!本站只为传递信息,我们不做任何双方证明,也不承担任何法律责任。文章内容若侵犯你的权益,请联系本站删除!
也许你还会对下面的内容感兴趣:
发表评论: