Learn the unfamiliar or weak knowledge points you encounter in PHP (to be continued)

Source: Internet
Author: User
Tags define function
I am welcome to join the group for all the unfamiliar or weak knowledge points I encountered in PHP (to be continued): 206981178. the summary is not very good, there may be a lot of simple things that I am not familiar with. please do not spray 1. related Variables in php & nbsp; the variable name must be a letter or underscore & quo learn unfamiliar or weak knowledge in PHP (to be continued)

Welcome to the IT personnel group: 206981178. learn together

The summary is not very good. maybe there are many simple things that are not familiar to me. please do not spray them.

1. related variables in php

The variable name must start with a letter or underscore.

Variable names can only contain letters, numbers, and underscores.

Variable names cannot contain spaces. If the variable name is composed of multiple words, it should be separated by underscores (for example, $ my_string) or begin with an uppercase letter (for example, $ myString ).

Main example:

$4 site = 'not Yun'; // illegal change name; starting with a number $ _ 4 site = 'not Yun'; // valid variable name; start with the following line: $ I site is = 'mansikka '; // valid variable name; Chinese
Predefined variables of php

Includes: $ _ SERVER, $ _ POST, $ _ GET, $ _ REQUEST,

Common examples:

$ A = "PHP Yanyan"; echo "gets the variable value through \ $ GLOBALS :". $ GLOBALS ['A']; // output: use $ GLOBALS to get the variable value: PHP Yanyan echo"
"; Echo" file name of the currently executed script: ". $ _ SERVER ['php _ SELF ']; // output: file name of the currently executed script:/study_php/2-3.php echo"
"; Echo" root directory of the script being executed :". $ _ SERVER ['document _ root']; // output: ROOT directory of the currently executed script: H:/wwwroot echo"
"; Echo" absolute path of the script being executed :". $ _ SERVER ['script _ filename']; // output: the absolute path of the currently executed SCRIPT: H: /wwwroot/study_php/2-3.php forced conversion of variable types PHP type forced conversion is very similar to in C: add the target type enclosed in parentheses before the variable to be converted.

The following mandatory conversions are allowed:

(Int), (integer)-convert to integer

(Bool), (boolean)-convert to boolean

(Float), (double), (real)-convert to floating point type

(String)-convert to string

(Array)-convert to an array

(Object)-convert to object

Variable type judgment PHP includes several functions to determine the type of the variable, such as gettype (), is_array (), is_float (), is_int (), is_object (), and is_string (). // Gettype () get the variable type
$ Str = "this is a string ";
$ Int = 9;
$ Bool = FALSE;
Echo "\ $ str:". gettype ($ str );
Echo"
";
Echo "\ $ int type:". gettype ($ int );
Echo"
";
Echo "\ $ bool type:". gettype ($ bool );
// Set the variable type
// Bool settype (mixed var, string type) sets the var type to type.
// The possible value of type is:
// "Boolean" (or "bool", starting from PHP 4.2.0)
// "Integer" (or "int", starting from PHP 4.2.0)
// "Float" (available only after PHP 4.2.0, and "double" used in earlier versions is disabled now)
// "String"
// "Array"
// "Object"
// "Null" (from PHP 4.2.0)
// If the call succeeds, TRUE is returned. if the call fails, FALSE is returned.
?>
Copyright: http://blog.csdn.net/yanfangphp
Deletion of variables
Unset () deletes the specified variable. it is a statement with no return value. an attempt to obtain the return value of unset () will cause a parsing error.
Unset ($ var); // delete a single variable
Unset ($ arr ['elem ']); // deletes an array element.
Unset ($ var1, $ var2, $ var3); // delete more than one variable

2. Related constants in php

The define function is used to define constants in php. constants are used to uppercase letters.
Once a constant is defined, it cannot be changed or undefined.
Do not add the $ symbol before the constant

// Define (ABC, "www.phpjc.cn"); // defines the constant ABC and assigns a value
// Define (SIZE, 100); // defines the constant SIZE.

Predefined Constants

PHP provides a large number of predefined constants to any script it runs. However, many constants are defined by different extension libraries. they only appear when these extension libraries are loaded, dynamically loaded, or included during compilation.
Description
The current row number in the _ LINE _ file.
The complete path and FILE name of The _ FILE.
_ FUNCTION name (new in PHP 4.3.0)
_ CLASS name (new in PHP 4.3.0)
_ METHOD _ class METHOD name (this is newly added in PHP 5.0.0)


Bit logical operators

Example name result
$ A and $ B And (logical and) TRUE, if both $ a And $ B are TRUE.
$ A or $ B Or (logical or) TRUE, if $ a Or $ B is TRUE.
$ A xor $ B Xor (logical exclusive or) TRUE. if either $ a or $ B is TRUE, but not both.
! $ A Not (logical Not) TRUE, if $ a is Not TRUE.
$ A & $ B And (logical And) TRUE, if both $ a And $ B are TRUE.
$ A | $ B Or (logical Or) TRUE. if $ a Or $ B is set to TRUE.

This method can also be output correctly (I only know ):

// Output a piece of text
Print < PHP Tutorial network is a professional website focusing on PHP resource sharing,
Strive to create a textbook-based PHP Tutorial network.
END;


The application method in the for loop:


/* Application 1. each condition has */
For ($ I = 1; $ I <= 10; $ I ++ ){
Print $ I ."-";
}
/* Apply 2, omitting 2nd expressions */
Print"
";
For ($ I = 1; $ I ++ ){
If ($ I> 10 ){
Break;
}
Print $ I ."-";
}
Print"
";
/* Apply 3, omit 3 expressions */

$ I = 1;
For (;;){
If ($ I> 10 ){
Break;
}
Print $ I ."-";
$ I ++;
}
Print"
";
/* Application 4 */

For ($ I = 1; $ I <= 10; print $ I. "-", $ I ++ );
Print"
";

/* Application 5 */
For ($ I = 1; $ I <= 10; $ I ++): print $ I; print "-"; endfor;


The application method in the while loop:

/* Application 1 */
$ I = 1;
While ($ I <= 10 ){
Print $ I ++ ."-";
}
Print"
";
/* Application 2 */
$ I = 1;
While ($ I <= 10 ):
Print $ I ."-";
$ I ++;
Endwhile;
Print"
";

/* Application 3 */
$ I = 1;
While ($ I <20 ):
Print $ I ."-";
$ I ++;
If ($ I> 10) break;
Endwhile;
// Www.phpjc.cn
?>


The continoe statement in PHP

$ I = 0;
While ($ I ++ <5 ){
If ($ I = 2) {// jump out, that is, I am 2 is not output
Continue;
}
Echo "I am $ I
";
}
?>

Coming off work... update tomorrow







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.