Method: 1. Use "for($i=0;$i
The operating environment of this article: Windows 10 system, ThinkPHP version 5, Dell G3 computer.
How to query the length of a one-dimensional array in thinkphp
for loop format
for($i=0;$i<count($arr);$i++) { echo $arr[$i]; }
Return the length of the array
$count = count($arr)
The front-end gets the array length
{$arr|count}
The example is as follows:
Create an IndexController.class in the ThinkPHP controller directory .php class file is used to explain how thinkphp finds the length of an array in a template file. Create a test() method to query data and pass it to the template.
Use the M method to instantiate the list model, query the data through the select() method, and save it in the $data variable. Pass the obtained data to the template using the assign() method, and display the template through the display() method.
In the template file, use the count method to obtain the length of the array, written as "{$data|count}".
#Open the test method in the index controller in the browser to view the results.
Summary:
1. In the index controller, create a test() method, use the M method to instantiate the list model, and pass select() ) method to query data.
2. In the test() method, pass the obtained data to the template using the assign() method, and display the template through the display() method.
3. In the template file, use the count method to obtain the length of the array, written as "{$data|count}".
Notes
If used in the if statement of a template, the writing method is "count($data)".
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to query the length of a one-dimensional array in thinkphp. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver Mac version
Visual web development tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.