search
HomePHP FrameworkThinkPHPHow to query the length of a one-dimensional array in thinkphp

Method: 1. Use "for($i=0;$i

How to query the length of a one-dimensional array in thinkphp

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.

How to query the length of a one-dimensional array in thinkphp

In the template file, use the count method to obtain the length of the array, written as "{$data|count}".

How to query the length of a one-dimensional array in thinkphp

#Open the test method in the index controller in the browser to view the results.

How to query the length of a one-dimensional array in thinkphp

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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

MinGW - Minimalist GNU for Windows

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

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Safe Exam Browser

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.