Home >Backend Development >PHP Tutorial >Use functions instead of require operations in php_PHP tutorial

Use functions instead of require operations in php_PHP tutorial

WBOY
WBOYOriginal
2016-07-20 11:17:32861browse

In order to reduce repeated code, it is often necessary to include header and footer. The most commonly used operations are require or require_once and other codes, but we can use another way to achieve this inclusion, write a function, For example, printHeader, as shown below, seems to be more troublesome to turn one line of code into two lines, but it can achieve some additional effects. For example, if we want each page to have a different title, we can pass parameters to this function (as shown below) Show).

function printHeader($title)
{
    require("../lib/header.php");
}

Also in header.php

<html>
    <head>
        <title><?= $title ?></title>
...

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/371984.htmlTechArticleIn order to reduce repeated code, it is often necessary to include header and footer. The most common operations we use are require or require_once, etc. code, but we can do it in another way...
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