Home Backend Development PHP Tutorial PHP3 Chinese Documentation Continued 4_PHP Tutorial

PHP3 Chinese Documentation Continued 4_PHP Tutorial

Jul 13, 2016 pm 05:23 PM
switch Chinese for how it document yes understand Know statement avoid

In order to understand the SWITCH statement and to avoid statement verbosity, it is important to know how it is executed. The SWITCH statement is executed line by line (in fact, statement by statement). At the beginning, no code is executed. Just when a After a CASE statement with the same value as the statement in the SWITCH expression is found, PHP continues to execute the statement until the end of the SWITCH body, or a BREAK statement. If you do not write a BREAK statement after a branch statement, PHP will continue execution. The following branch statement. For example: /* example 3 */ switch ($i) { case 0: print "i equals 0"; case 1: print "i equals 1"; case 2: print "i equals 2"; } Here, if $i is equal to 0, PHP will execute all print statements. If $i is equal to 1, PHP will execute the remaining two print statements, and only when $i is equal to 2, you can get what you expect. As a result, only 'I equals 2' is displayed. So don't forget the BREAK statements after each branch statement (even if you may want to avoid providing them in certain circumstances). A special branch is the default branch. This A branch can match anything that is not matched by any other branch. For example: /* example 4 */ switch ($i) { case 0: print "i equals 0"; break; case 1: print "i equals 1"; break; case 2: print "i equals 2"; break; default: print "i is not equal to 0, 1 or 2"; } Another fact worth mentioning is that the CASE expression can be any expression that computes a scalar type, as well. That is, integers or reals and chars, arrays and objects will not cause PHP to crash, but they do not make any sense. REQUIRE The REQUIRE statement uses the specified file instead of itself, much like the #include statement in C resemblance. This means that you cannot put a require() statement inside a loop and expect it to include the contents of a different file on each iteration. To achieve this, use the INCLUDE statement. require (header.inc); INCLUDE The INCLUDE statement includes and calculates the specified file. It will be performed every time an INCLUDE statement is encountered. Therefore, you can use the INCLUDE statement in a loop body to include some different files. $ files = array (first.inc, second.inc, third.inc); for ($i = 0; $i items[$artnr] += $num; } // Take $num articles of $artnr out of the cart function remove_item ($artnr, $num) { if ($this->items[$artnr] > $num) { $this->items[$artnr] -= $num; return true; } else { return false ; } } ?> As shown above, a class named Cart is defined. This class consists of multiple arrays describing items and functions for adding items and deleting items. Class is a type, that is to say, it is. Design blueprint of actual variables. You can create a variable group and some new operations on them according to the design: $cart = new Cart; $cart->add_item("10", 1); As shown above, create. An object of type class Cart is created. The function add_item() in this object is called to add an item with item number 10. Class can be extended by other Classes. It has all the variables and functions of the basic class and you can also add your own extended definitions. To do this, you need to use the extended definition keyword class Named_Cart extends Cart { var $owner; function set_owner ($name) {. $this->owner = $name; } } The above defines a class named Named_Cart. This class has all the variables and functions contained in the Cart class, and also adds a variable $owner and the function set_owner( ). You can create a named cart and get the name of the cart owner. You can also use ordinary functions belonging to class cart in class Named_Cart. $ncart = new Named_Cart; // Create a named cart $ncart->set_owner ("kris"); // Name that cart print $ncart->owner; // print the cart owners name $ncart->add_item ("10 ", 1); // (inherited functionality from cart) In the function of this class, the variable $this represents this object. Within the current object, you can use $this->something to access any variables and functions.When you create a new class, there is a constructor function that will be called automatically. If the name of a function is the same as the name of the class, then it becomes a constructor: class Auto_Cart extends Cart { function Auto_Cart () { $this->add_item ("10", 1); } } In the above example, A class named Auto_Cart is defined, which adds a constructor function to the original Cart class. This constructor function initializes the Cart class by adding an item number each time a class is created. for an item of 10. Constructors can also display some information, which can be selected at will, which makes them very useful. class Constructor_Cart { function Constructor_Cart ($item = "10", $num = 1) { $this->add_item ($item, $num); } } // Shop the same old boring stuff $default_cart = new Constructor_Cart; // Shop for real... $different_cart = new Constructor_Cart ("20", 17);

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/532208.htmlTechArticleIn order to understand the SWITCH statement and to avoid verbose statements, it is very important to know how it is executed. The SWITCH statement is one line. Executed one line (actually, one statement at a time). At the beginning...
Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Setting up Chinese with VSCode: The Complete Guide Setting up Chinese with VSCode: The Complete Guide Mar 25, 2024 am 11:18 AM

VSCode Setup in Chinese: A Complete Guide In software development, Visual Studio Code (VSCode for short) is a commonly used integrated development environment. For developers who use Chinese, setting VSCode to the Chinese interface can improve work efficiency. This article will provide you with a complete guide, detailing how to set VSCode to a Chinese interface and providing specific code examples. Step 1: Download and install the language pack. After opening VSCode, click on the left

Tips for solving Chinese garbled characters when writing txt files with PHP Tips for solving Chinese garbled characters when writing txt files with PHP Mar 27, 2024 pm 01:18 PM

Tips for solving Chinese garbled characters written by PHP into txt files. With the rapid development of the Internet, PHP, as a widely used programming language, is used by more and more developers. In PHP development, it is often necessary to read and write text files, including txt files that write Chinese content. However, due to encoding format problems, sometimes the written Chinese will appear garbled. This article will introduce some techniques to solve the problem of Chinese garbled characters written into txt files by PHP, and provide specific code examples. Problem analysis in PHP, text

Detailed explanation of Word document operation: merge two pages into one Detailed explanation of Word document operation: merge two pages into one Mar 26, 2024 am 08:18 AM

Word documents are one of the most frequently used applications in our daily work and study. When working with documents, you may sometimes encounter a situation where you need to merge two pages into one. This article will introduce in detail how to merge two pages into one page in a Word document to help readers handle document layout more efficiently. In Word documents, the operation of merging two pages into one is usually used to save paper and printing costs, or to make the document more compact and neat. The following are the specific steps to merge two pages into one: Step 1: Open the Word that needs to be operated

Practical Tips: How to use the trim function in PHP to process Chinese spaces Practical Tips: How to use the trim function in PHP to process Chinese spaces Mar 27, 2024 am 11:27 AM

In PHP programming, spaces are often encountered when processing strings, including Chinese spaces. In actual development, we often use the trim function to remove spaces at both ends of a string, but the processing of Chinese spaces is relatively complicated. This article will introduce how to use the trim function in PHP to process Chinese spaces and provide specific code examples. First, let us understand the types of Chinese spaces. In Chinese, spaces include not only common English spaces (space), but also some other special spaces.

How to view Golang function documentation in the IDE? How to view Golang function documentation in the IDE? Apr 18, 2024 pm 03:06 PM

View Go function documentation using the IDE: Hover the cursor over the function name. Press the hotkey (GoLand: Ctrl+Q; VSCode: After installing GoExtensionPack, F1 and select "Go:ShowDocumentation").

Detailed explanation of the reasons why VSCode Chinese interface settings fail Detailed explanation of the reasons why VSCode Chinese interface settings fail Mar 25, 2024 pm 05:15 PM

In the development process using Visual Studio Code (VSCode), sometimes the problem of setting the Chinese interface fails. This situation may confuse users because the Chinese interface has been selected during the installation process, but during actual use they find that the English interface is still displayed. Next, we will explore the possible causes of this problem in detail and give specific code examples to solve this problem. First of all, one of the main reasons for the failure of VSCode Chinese interface settings may be the software

PHP Tip: One line of code to convert numbers to Chinese uppercase PHP Tip: One line of code to convert numbers to Chinese uppercase Mar 26, 2024 am 11:09 AM

PHP Tips: One Line of Code to Convert Numbers to Chinese Uppercase When developing PHP programs, sometimes you need to convert numbers to Chinese uppercase, for example, convert 12345 to "twelve thousand three hundred and forty-five". Below we will introduce a simple and practical way to implement this function in one line of code. //Convert numbers to Chinese uppercase functionnum2chinese($num){$array=array('zero','one','two','three','four',

What should I do if an extension error occurs when setting Chinese in VSCode? What should I do if an extension error occurs when setting Chinese in VSCode? Mar 26, 2024 am 10:21 AM

What should I do if an extension error occurs when setting Chinese in VSCode? With the continuous development of computer technology, programmers often use various development tools in their daily work to improve efficiency and the quality of written code. Among them, Visual Studio Code (VSCode for short) is a powerful and flexible code editor that is favored by programmers. However, sometimes when setting the interface language of VSCode to Chinese, you may encounter some extension errors, which brings some difficulties to your work.

See all articles