PHP Syntax _php Tutorial

Source: Internet
Author: User
PHP basic syntax looks familiar. Running result: Hello, world! The variable is marked "$". You can also put the above "Hello, world!" Write the following code: String concatenation is the use of "." (a period of English); Other arithmetic symbols for numbers are the same as you would expect: Run Result: Hello 6 people! PHP has a complete operator that functions as you would expect-especially if you have a knowledge background of C or C + +. A good rule of thumb for using PHP is this: "If you have a problem, try it first and it's likely to succeed." "As in Perl, a string is enclosed in double quotes, which causes the variables to be replaced by values, but not if enclosed in single quotes." Therefore, the following code: Running result: Hello, susannah! Hello, $name! Note that the string "" is a newline symbol, just like in Perl or C. However, this is only valid within strings enclosed in double quotes. Variable PHP can use environment variables as general variables. This includes the environment variables set by the server for a CGI program (even when you execute PHP in a modular manner). Therefore, if the page http://www.domain.com/farm/cattle/cow-cow.cow.html includes the following code: It sets the output [/farm/cattle/cow-cow-cow.html] array to use square brackets ([and]) to set the array index (general or associativity): $fruit [0] = banana; $fruit [1] = papaya; $favorites [Animal] = turtle; $favorites [monster] = cookies; If you assign a value to an array, but the index is blank, PHP places the object at the end of the list. The above declaration of the variable $fruit is the same as the result of the following code: $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; An easy way to create an array is the array () function: $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)); The built-in function count () indicates how many elements are in an array: $fruit = Array (Banana,papaya); Print count ($fruit); Get the following results for 2 control structures you can take advantage of the looping structure such as for and while:for ($i = 4; $i < 8; $i + +) {print "I have eaten $i bagels today."; "Result I have EA Ten 4 Bagels today. I have eaten 5 bagels today. I have eaten 6 bagels today. I have eaten 7 bagels today. Can also be written as $i = 4; while ($i < 8) {print "I havE eaten $i bagels today. "; $i + +; You can use the control structure if and elseif:if ($user _count > $) {print "The site is busy right now!";} elseif ($user _count > 100) { Print "The site is a sort of active right now!"; else {print "The site is lonely-only $user _count user logged on."; The rule of thumb with operators can also be applied to control structures. You can also use Switch,do...while, even the?: Structure.

http://www.bkjia.com/PHPjc/531893.html www.bkjia.com true http://www.bkjia.com/PHPjc/531893.html techarticle PHP basic syntax looks familiar. Running result: Hello, world! The variable is marked "$". You can also put the above "Hello, world!" Write the following code: string concatenation is ...

  • 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.