PHP syntax_PHP tutorial

WBOY
Release: 2016-07-13 17:27:09
Original
856 people have browsed it

The basic PHP syntax looks familiar. Running results: Hello, World! The variable is marked with "$". You can also write the above "Hello, World!" as the following code: The concatenation of strings is marked with "." (an English period); other numerical operation symbols are as you would expect. Same: Result: Hello 6 people! PHP has a complete set of operators that function as you would expect - especially if you have a background in C or C++. A good rule of thumb when working with PHP is: "When you have a problem, try it first and you'll probably succeed." As in Perl, a string is enclosed in double quotes, which will cause the variables within it to be replaced by their values, and if Enclosed in single quotes, it won't. Therefore, the following code: Running result: Hello, Susannah! Hello, $name! Note the " ” is the newline symbol, just like in Perl or C. However, this only works within a string enclosed in double quotes. Variables PHP can use environment variables as normal variables. This includes variables set by the server for a CGI program. environment variables set (even when you execute PHP as a module). So if the page http://www.domain.com/farm/cattle/cow-cow.cow.html includes the following code: it will Output [/farm/cattle/cow-cow-cow.html] Arrays Use square brackets ([ and ]) to set array indexes (general or associative): $fruit[0] = banana; $fruit[1] = papaya; $favorites[animal] = turtle; $favorites[monster] = cookie; If you assign a value to the array, but the index is blank, PHP will place the object at the end of the array. The above declaration of the variable $fruit is the same as the following code. The result is the same: $fruit[] = banana; $fruit[] = papaya; You can also use multidimensional arrays: $people[David][shirt] = blue; $people[David][car] = minivan; $people [Adam][shirt] = white; $people[Adam][car] = sedan; A convenient way to create an array is array(). The function is: $fruit = array(banana,papaya); $favorites = array(animal = > turtle, monster => cookie); or $people = array (David => array(shirt => blue, car => minivan), Adam => array(shirt => white, car => sedan)); built-in The function count() indicates how many elements there are in an array: $fruit = array(banana,papaya); print count($fruit); The following results are obtained 2 Control structures You can use loop structures such as for and while: for ($i = 4; $i 200) { print "The site is busy right now!"; } elseif ($user_count > 100) { print "The site is sort of active right now!"; else { print "The site is lonely - only $user_count user logged on."; } The same rules of thumb for operators apply to control structures as well. You can also use switch, do...while, or even the ?: construct.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/531893.htmlTechArticlePHP basic syntax looks familiar. Running results: Hello, World! The variable is marked with "$". You can also write the above "Hello, World!" as the following code: The concatenation of strings is...
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template