{Php control flow}

Source: Internet
Author: User
{Php control flow} Table of Contents introduction if else elseif/else if switch
While do-while for foreach

Break continue goto declare return require include require_once include_once

### Differences between include, include_once, require, and require_once statements in php files


1. include () format 1: include (path/filename); format 2: include 'filename'; 1. include () the statement will contain a file at the location where it is called. The data that contains a file is the same as the data that copies the file where the statement is located.

Effect. Parentheses can be ignored when include () is used. 2. you can execute the include () statement according to the conditions. The use of include () in conditional statements has a strange phenomenon. it must be enclosed in statement block braces or

Enclose other statements.

2. include_once () format 1: include_once (filename); format 2: include_once 'filename'; include_once () functions are the same as include functions, however, it first verifies whether the file is included. If it already exists, it will not be executed

Include_once. Otherwise, the file must be included. This is the same as include. 3. require () format 1: require (filename); format 2: require 'filename'; require () is largely the same as include, all include a template file to the location where the require call is located. There are two important differences between require and include:

First, regardless of the location of require, the file will be included in the script where require appears. For example, even if require is placed in the if language where the calculation result is false

The specified file is still contained.

The second important difference is that when a require error occurs, the script stops running, and the script continues to run when the include is used. 4. the require_once () format is 1: require_once (filename); the format is 2: require_once 'filename'; as the website grows larger, some files may be repeatedly contained. This may not be a problem, but after modifying the variable of the contained file, it is because

If the file contains the original file, this may not happen. Another problem may also occur, that is, the conflict of letters in the file. Use

Require_once can solve these problems. The require_once function ensures that the file is only contained once. If you encounter require_once and try to include the same file later, it will be ignored. When an error occurs when the include () file is introduced, the script continues to execute require (). When an error occurs when the file is introduced, the script does not continue to execute

### Alternative process control syntax

PHP provides alternative syntaxes for process control, including if, while, for, foreach, and switch.

The basic form of the alternative syntax is to replace left curly braces ({) with colons (:) and right curly braces (}) with endif;, endwhile;, endfor;, endforeach; and endswitch ;.


$b) { echo " 123 " ;} elseif ($a == $b) { echo " 456 " ;} else { echo " 789 " ;} ?>




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.