将数组转化为键值对
2016-04-08 15:10
190 查看
/**
* 将数组转化为键值对
* @param type $array
* @param type $type
* @param type $exclude
* @return type
*/
public function array_to_sql($array, $type = 'insert', $exclude = array()) {
$sql = '';
if (count($array) > 0) {
foreach ($exclude as $exkey) {
unset($array[$exkey]); //剔除不要的key
}
if ('insert' == $type) {
$keys = array_keys($array);
$values = array_values($array);
$col = implode("`, `", $keys);
$val = implode("', '", $values);
$sql = "(`$col`) values('$val')";
} else if ('update' == $type) {
$tempsql = '';
$temparr = array();
foreach ($array as $key => $value) {
$tempsql = "`$key` = '$value'";
$temparr[] = $tempsql;
}
$sql = implode(",", $temparr);
}
}
return $sql;
}
* 将数组转化为键值对
* @param type $array
* @param type $type
* @param type $exclude
* @return type
*/
public function array_to_sql($array, $type = 'insert', $exclude = array()) {
$sql = '';
if (count($array) > 0) {
foreach ($exclude as $exkey) {
unset($array[$exkey]); //剔除不要的key
}
if ('insert' == $type) {
$keys = array_keys($array);
$values = array_values($array);
$col = implode("`, `", $keys);
$val = implode("', '", $values);
$sql = "(`$col`) values('$val')";
} else if ('update' == $type) {
$tempsql = '';
$temparr = array();
foreach ($array as $key => $value) {
$tempsql = "`$key` = '$value'";
$temparr[] = $tempsql;
}
$sql = implode(",", $temparr);
}
}
return $sql;
}
相关文章推荐
- DataSanp App与Rest, WebBroker App的区别
- Fragment嵌套ViewPager切换后数据消失ViewPager空白问题
- 3.jenkins使用maven构建项目
- shell排序的java代码
- 使用工厂模式的CRUD操作
- 错误修复:java.lang.NoClassDefFoundError: org/apache/xerces/jaxp/datatype/XMLGregorianCalendarImpl$Parser
- Bitmap.createBitmap
- mtt 有关 ghostview octave
- 实现经常使用的配置文件/初始化文件读取的一个C程序
- 爬虫_监控某个元素所有事件
- oracle命令大全
- 海康rtsp抓包分析
- js生成验证码并验证
- MYSQL常用调优策略
- 水果手机 Safari transform rotateY 不兼容问题
- 递归模式学习(recursion)
- Flex Number 存入Oracle中,去掉小数点
- 序列化
- 优秀程序员的10个习惯
- 【即学即用】——一个工程实例来学习 Makefile