Why use Comments?
If you don’t work on the source code for some time, it’s easy to forget what the code does.Bạn vẫn xem: Php include & require
Commenting the source code helps remember what the code does.Bạn đang xem: Php include_once & require_once tutorial in hindi / urdu
Commenting source code is also very important when multiple developers have to lớn work on the same project. The changes made by one developer can be easily understood by other developers by simply reading the comments. As the best practice, you must have 3 lines of comments for every 10 lines of codeIn this tutorial, you will learn-
PHP Comments
Comments help us to understand the code Comments are explanations that we include in our source code. These comments are for human understanding. Single line comments start with double forward slashes // and they over in the same line. Multiple line comments start with a forward slash followed by the asterisk /* & end with the asterisk followed by the forward slash */. The diagram below shows a PHP file with both multiple line và single line comments PHP Example
PHP Include và PHP Include_once
The “include” php statement is used to lớn include other files into a PHP file. It has two variations, include and include_once. Include_once is ignored by the PHP interpreter if the tệp tin to be included. The include statement has the following syntax The include_once statement has the following syntax HERE, “Include/include_once” is the statement that includes tệp tin “"file_name"” is the name of the file to be included.Example : Include / Include_once
Suppose you are developing a website that contains the same navigation thực đơn across all the pages. You can create a common header then include it in every page using the include statement Let’s see how this can be done. We will create 2 files names header.php, index.php Below are the codes for; header.php HomeAbout usServicesContact Us index.php The header page above will outputPHP Require và PHP require_once
Example : Require
Suppose we are developing a database powered application. We can create a configuration file that we can include in all pages that connect khổng lồ the database using the require statement. Config.php Let’s now look at the sample code that requires the config file.Xem thêm: Đọc: Phương Pháp Dạy Con Không Đòn Roi Vọt, 10 Cách Dạy Con Không Cần Dùng Roi Vọt
Pages_model.phpPhp include vs require
The difference between include / requireIssues a warning when an error occurs | Does not issue a warning |
Execution of the script continues when an error occurs | Execution of the script stops when an error occurs. |