PHP 数据库查询结果转换数组后进行再查询过滤
2016-06-13 20:45
736 查看
//filterArrays($category_result,array(array("col"=>"id","val"=>"49"),array("col"=>"borrow_nid","val"=>"20160500064")));
function filterArrays($list = array(),$where = array()){
$index = 0;
foreach ($list as $key => $value){
$mached = 0;
foreach($where as $wk=>$wv){
//self::log($wv['col']);
//self::log($wv['val']);
if($value[$wv['col']] == $wv['val']){
$mached++;
}
}
if($mached==count($where)){
$data['row'] = $value;
$data['index'] = $index;
return $data;
}
/*
foreach ($value as $_key => $_value){
if($_key==$where['col'] && $_value==$where['val']){
$data['row'] = $value;
$data['index'] = $index;
return $data;
}
}
*/
$index++;
}
$data['row'] = null;
$data['index'] = -1;
return $data;
}
function filterArrays($list = array(),$where = array()){
$index = 0;
foreach ($list as $key => $value){
$mached = 0;
foreach($where as $wk=>$wv){
//self::log($wv['col']);
//self::log($wv['val']);
if($value[$wv['col']] == $wv['val']){
$mached++;
}
}
if($mached==count($where)){
$data['row'] = $value;
$data['index'] = $index;
return $data;
}
/*
foreach ($value as $_key => $_value){
if($_key==$where['col'] && $_value==$where['val']){
$data['row'] = $value;
$data['index'] = $index;
return $data;
}
}
*/
$index++;
}
$data['row'] = null;
$data['index'] = -1;
return $data;
}
相关文章推荐
- Yii2配置url重写
- PHP入门
- IO流 文件读取和写入 FileInputStream和FileOutputStream
- php总结
- 自己动手写RTP服务器——关于RTP协议
- PHP学习笔记-PHP与Web页面的交互1
- 使用PHP实现验证码
- php笔记1
- 第24课:Spark Streaming的Transformation、Action、Input和Output源码图解
- [PHP-Socket] Socket Programming in PHP
- php
- php函数serialize()与unserialize()
- PHP通过正则表达式获取网页中的所有图片
- CodeIgniter学习笔记 Item1--CI简介与MVC设计模式
- PHP将数字金额转化为中文人民币大写
- smtp cmd 测试 smtp发送邮件 cmd发送邮件
- php导入大量数据到mysql性能优化技巧
- Error while istalling Drupal 7
- PHP|开发必知的良好实践
- php 两张图片合成