PHP basic syntax!

Source: Internet
Author: User
<? PHP // Add a variable name to $ var_str = "sample Val"; echo $ var_str; /*************************************** * *********** // The variable name is case sensitive, however, function names are case-insensitive. // In PHP, all the recommended variable names are in lower case, and different words are separated by underscores. // For example: $ font_size $ user_name $ user_name_id /********************************* * ***************** // the initial value of the variable // It is generally best to give the initial value during definition: see the following code $ var1; echo $ var1; // $ Var = ""; echo $ var1. "ADB"; // $ Var = ""; echo $ var1 + 10.5; // $ Var = 0; if ($ var) {// $ Var = false; echo "true ";} // The above is the consequence of not initializing it, resulting in different initial values under different circumstances. /*************************************** * ************* // You can use isset () check whether the variable is set. $ Var2; If (! Isset ($ var2) {echo "var2 is not set";} $ var2 = NULL; If (! Isset ($ var2) {echo "var2 is not set";} $ var2 = ""; if (isset ($ var2) {echo "var2 is set ";} // pay attention to the following: // $ var3 = 1, var4 = 2, var5 = 3; // The preceding statements are incorrect. In PHP, a statement is not allowed to define multiple variables. /*************************************** * *********** // reference the variable $ var6 = & $ var1; $ var7 = "the default string"; $ var8 = & $ var7; $ var8 = "the string change"; echo $ var8; // The string change; echo $ var7; // The string change; // some problems can be seen here. In fact, var8 is equivalent to the var7 pointer. // Direct to the address of var7. Modify the value of var8 as the value of var7. /*************************************** * *********** // Variable $ STR = "name "; $ name = "jhone"; $ out_str = $ STR; // equivalent to $ out = $ name; $ out_str =$ {$ STR}; // What about the above Code, add $ in front of $ STR, and use the Value Name of $ STR as the name of the new variable. // This Is Why $ out_str =$ $ STR; equivalent to $ out = $ name; // if you change the value of $ STR, the value of $ out_str will also be modified. // Use the variable $ var_name = "str"; $ var9 = "the first string"; $ var10 = "the second string" in the for loop structure "; $ var11 = "the third string"; for ($ I = 9; $ I <12; $ I ++) {echo =$ {$ var_name. $ Si };}// here. indicates a link character. It is not an attribute symbol in C ++ or Java .; /*************************************** * ************ // variable scope // global variables: variables outside the function. By default, they can only be used outside the function. The function must be used internally and must be declared globally. // local variable: $ type = "book" in the function; $ number = "Number"; function fun1 () {Global $ type; $ type = "Clothes "; $ number = "skirt";} fun1 (); echo "the type is ". $ type; echo "the number is ". $ number; // Of course, you can use the predefined global variable data $ globals in PHP to access all variables. Fun2 () {$ globals ['type'] = "Clothes";} fun2 (); echo "the type is ". $ type; /*************************************** * ************ // static variables // The format is as follows: // static $ var_name; function fun3 () {$ num = 0; echo num; num ++;} function fun4 () {static $ num = 0; echo num; num ++;} For ($ I = 0; $ I <10; $ I ++) {fun3 () ;}for ($ I = 0; $ I <10; $ I ++) {fun4 ();} /** 0000000000*0123456789 *//************************** * ************************ // A set of pre-defined variables // provides an array, contains server, user environment, client input, and other data. // These predefined arrays automatically take effect within the global scope of the current script, // directly used in a function without the need to declare a with the Global keyword. // This is different from the custom global variable, so it is called a super global variable. // The previous $ globals data is a super global variable. // In PHP, only the pre-defined array is a super global variable, and there is no sub-defined mechanism for the super global variable. $ _ Server array // data created by the Web server, such as header information, file path, and server name. // Print_r ($ _ server ); /*************************************** * *********** // $ _ env array // all environment variables set in the PHP server's hydrogen operating system. Print_r ($ _ env ); /*************************************** * *********** // $ _ Get array // the variable that the client passes to the script through the URL request. // by "? "The symbol follows the URL address and is given in the form of a {Variable = value} data pair. Multiple data pairs are separated by &. // http: // localhost: 8080/admin/test. PHP? Name = czh & City = Changsha // contains two variables: $ _ Get ["name"]; $ _ Get ["city"]/***************************** * ****************** // $ _ post array // the variable that the client transmits to the script through post. /*************************************** * *********** // $ _ cookie array /******************* * ******************************* // $ _ file Array // The client uploads the file information through post. /* <form action = "" post = "multipart/form-Data"> <input type = "file" name = "FILENAME"/> </form> *//************************************* * ************* // $ _ Request array // use a version later than php4.0, includes $ _ Get, $ _ post, $ _ all content in cookies /********************************* * ***************** // $ _ Session array // used to implement session /******* **************************************** * *** // array operator // PHP provides a set of array-specific operators. Include: Union operator "+", equal operator "=" Full operator "=" // unequal operator "! = "And" <> "incomplete operators "! = "/************************************ * ************** // Special operators // error operators @ ($ A/$ B + $ C ); @ session_start (); // The error message will be ignored /********************************* * ***************** // execution operator ''(unquoted) // foreach loop (only used for arrays) foreach (array_exprssion as $ key => $ value) {}// while traversing the array, also copy the index name of the element to the variable key?>

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.