Too many PHP templates IF elseif judgment how to solve

WBOY
Release: 2016-08-04 09:19:31
Original
1642 people have browsed it

To use thinkphp to develop templates, you need to write a lot of judgments to read the desired data. For example, you need to write 30 IF ELSEIF judgments. Will it affect the page speed? Is there a better solution

Reply content:

To use thinkphp to develop templates, you need to write a lot of judgments to read the desired data. For example, you need to write 30 IF ELSEIF judgments. Will it affect the page speed? Is there a better solution

If the level of the set is very deep, then it is better for you to change your logic.
If the level is not deep, it is normal. You can use switch, or extract some if conditions that need to be judged, and convert them into bool variables on the back end.

The first rendering of the page will definitely be slower. You can use caching in the future. It is normal to have if else in the module. .

The data is parsed in advance in the background and then transmitted to the front desk.

Use switch for the template

If there are more than two ifelse, it is recommended to use switch

Give the semaphore
and then use switch

30 if elseifs? So many??
You can use switch case to simplify if elseif statements

It’s best to use arrays

Customize a function, write these logic into the function, and then call it in the template. As for many judgments, if you can change the background logic, simplify it.

You should look at your business logic to see if it can be optimized

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template