Home>Article>PHP Framework> What are the differences between find and select in thinkphp?
Difference: 1. find() will find the first piece of data that meets the conditions and return a one-dimensional array; while select() will find all the data that meets the conditions and return a two-dimensional array. 2. The find() result value uses "$data["key name"]", while the select() result value uses "$data[0]["key name"]".
The operating environment of this tutorial: Windows 7 system, thinkphp version 5, DELL G3 computer.
thinkphp is a relatively good PHP development framework that can quickly develop an MVC architecture management system. We need to use the select() and find() methods. Both methods can return data set arrays, but What's the difference? First, take a look at my code comparison:
$tech=M('techlevel','HR_CS_','DB_CONFIG2'); $Data=$tech->where('id=1')->find(); dump($Data); $Data=$tech->where('id=1')->select(); dump($Data);
Result:
array(6) { ["ID"] => int(1) ["TechLevel"] => string(2) "10" ["Remark"] => string(4) "��" ["CreateDate"] => string(19) "2013-03-14 15:14:38" ["CreateBy"] => string(5) "admin" ["ROW_NUMBER"] => string(1) "1" } array(1) { [0] => array(6) { ["ID"] => int(1) ["TechLevel"] => string(2) "10" ["Remark"] => string(4) "��" ["CreateDate"] => string(19) "2013-03-14 15:14:38" ["CreateBy"] => string(5) "admin" ["ROW_NUMBER"] => string(1) "1" } }
As can be seen from the above code, find() returns a one-dimensional array, and select() returns a two-dimensional array. Therefore, there are differences in the values. For one-dimensional arrays, $data["TechLevel"] is used, and for two-dimensional arrays, $data[0]["TechLevel"] is used. Since I didn't understand this usage at the beginning, it took a day of debugging. It’s not worth it either. Finally, with the dump method, we can see the difference between the two methods!
[Related tutorial recommendations:thinkphp framework]
The above is the detailed content of What are the differences between find and select in thinkphp?. For more information, please follow other related articles on the PHP Chinese website!