How to reuse the IF condition code in PHP

Source: Internet
Author: User
PHP Code Reuse

I have an if condition (which is a combination of many expressions) and is used on many pages, but the condition is changing at any time, such as:
if (condition)
Statement

How can I reuse the code for this condition? Thank you so much!


Reply to discussion (solution)

Define

if (function (AFAEFAE))
Encapsulate your conditional call into a function, called according to a different parameter.

$expr = ' conditional expression ';
if (eval ("Return $expr;")) {
...
}
But it is necessary to ensure that the variables that participate in the operation exist

if (function (AFAEFAE))
Encapsulate your conditional call into a function, called according to a different parameter.

The part of the change is extracted as a parameter, and the contents of the package function are left unchanged.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.