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 & requireCommenting the source code helps remember what the code does.
Bạn đang xem: Php include_once & require_once tutorial in hindi / urduCommenting 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 code
In this tutorial, you will learn-
PHP CommentsComments 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_onceThe “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_onceSuppose 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 output
PHP Require và PHP require_once
Example : RequireSuppose 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.
Php include vs requireThe difference between include / require
|Issues 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.|