Home>Article>PHP Framework> What are the differences between find and select in thinkphp?

What are the differences between find and select in thinkphp?

青灯夜游
青灯夜游 Original
2021-09-18 12:59:41 3109browse

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"]".

What are the differences between find and select in thinkphp?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn