Call a function from another PHP file

Содержание
Introduction
Create an array
Related articles

Introduction

It is often useful to split site code into several files in advance, to avoid working with a «bedsheet» tens of thousands of lines long.

Example

Suppose you have a file index.php and a file utils.php

In the file utils.php There is a make_head function to call from a file index.php passing the lang and title arguments

Example make_head function

<?php // This is utils.php function make_head($lang, $title) { echo' <!DOCTYPE html> ' echo' <html lang="'.$lang.'"> <head> <title>'.$title.'</title> </head> } ?>

Calling from a file

<?php // This is index.php // Assign values to variables $lang = 'ru' $title = 'URN.SU' // Include utils.php require_once('utils.php'); // Call the function with two arguments make_head($lang, $title); ?>

Note that I am not saying this is how you should do it. Just showing that it is possible to do it this way.

Article author: Andrei Olegovich

Похожие статьи
Development with PHP
Arrays in PHP
Date and Time in PHP - basics
How to display time of multiple timezones in PHP
How to add variable to url in PHP
json_decode
How to get screen size with PHP
Call function from another file
Premature end of chunk coded message body: closing chunk expected
Generate unique random numbers with PHP
Check your HTTP_USER_AGENT
Compare two dates
OOP
Namespaces in PHP
Comments in PHP
Cookies
PHP sessions
Authentication and Authorization in PHP 8
PHP linters we use
PHP errors: case studies
card_from_db(): banner card from a DB row
PHP versions: history in brief
Creating rules in .htaccess
require, require_once, include, include_once
Deduplication in PHP
PHP course: zero to hero in 50 lessons

Search this site

Subscribe to Telegram channel @aofeed to follow new articles and updates to old ones

Go to channel

@aofeed

Ask a question in the Telegram group

@aofeedchat

Contacts and cooperation:
I recommend our hosting beget.ru
Write to info@urn.su if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: