where 方法
1. 功能:生成查询条件(AND)
where方法是查询构造器的核心,是整个数据表查询的精华所在,也是ThinkPHP 5 与之前版本区别最大的地方之一,请一定要认真学习,理解透彻!
2. 源码:
1、/thinkphp/library/think/db/Query.php
where 和 whereOr 方法源码:
/**
* 指定AND查询条件
* @access public
* @param mixed $field 查询字段
* @param mixed $op 查询表达式
* @param mixed $condition 查询条件
* @return $this
*/
public function where($field, $op = null, $condition = null)
{
$param = func_get_args(); //获取参数列表数组
array_shift($param); //删除第一个元素
$this->parseWhereExp('AND', $field, $op, $condition, $param);
return $this;
}
分析:
首先用func_get_args函数获取到全部参数,打包到一个索引数组中;
再用array_shift函数使参数数组中的第一个元素出列,即单独取出:字段名;
pars