PHP Learning Summary

Source: Internet
Author: User
Tags php foreach scalar
1,

echo "Welcome to imooc!"; Output string

?>

2, strings are enclosed in "or", two characters can be used. Connected

3, Notes

//

4, line break


5. Variable names must be identified by the $ symbol

6, the "Var_dump" function can display the data types of our variables.

Var_dump ($var _name);
Var_dump ($n);

7, in PHP, variable names are case-sensitive

8. Array definitions

$var _array=array ("123");

9, you do not have to declare the variable's data type to PHP, and PHP automatically converts the variable to an automatic data type.

10, Scalar Type-Boolean type Boolean

Case insensitive

11,

Scalar type-integral type

Integral type (integer): Similar to a common integer. It can be specified in decimal, octal, hexadecimal. Decimal is the daily use of numbers, octal, the number must be added "0" (this 0 is the Arabic numeral 0, is not the English letter "ou" oh), hexadecimal, the number must be added "0x" (this 0 is also the Arabic numeral 0, not "O" oh). Such as:

 
  

12.

Scalar types-floating-point type

Floating-point (floating-point, double-precision, or real-number), which is usually said to be decimals, can be represented by a decimal point or by scientific notation. The scientific notation can be used in lowercase e, or in uppercase E. For example:

 
  


13.

Scalar Type-string (2)

First scenario: Embedding double quotes in single quotes, embedding directly

Second scenario: Embedding single quotes in double quotes, embedding directly

The third scenario: using the escape character "\",
$str _string3 = ' A Q: \ ' Can you tell me the URL? \'';
14,

When a variable is enclosed in double quotes, the variable is concatenated with the contents of the double quotation mark;

When a variable is included in a single quotation mark, the variable is exported as a string.

15, what happens when my string is long?


<<<>
I have a little donkey, I never ride.
One day I was on a whim, riding to the market.
I had a little whip in my hand and I was proud of it.
I do not know how to go, I fell a mud.
GOD;

In the end of the line, be sure to start another line, and this line except "GOD", and ";" After the end, can not have any other characters, before and after can not have,


16, resources

Resources are created and used by specialized functions, such as open files, data connections, graphical canvases

A. read File Resources

$file _handle=fopen ("/data/webroot/resource/php/f.txt", "R");
if ($file _handle) {
It then uses a while loop (described in detail in the loop structure in the following language structure statement) to read the file line by row, and then output the text for each line
while (!feof ($file _handle)) {//Determines whether to the last row
$line = fgets ($file _handle); Reading a line of text
Echo $line; Output a line of text
echo "
"; Line break
}
}
Fclose ($file _handle);//Close file resource

20,

The second special type-null type,


Null (NULL): null is a null type, is not case sensitive, the null type has only one value, indicating that a variable has no value, when it is assigned to NULL, or has not yet been assigned, or is unset (), the variables are considered NULL in three cases.

Not sensitive to case


eg. $var 3 = "Happy Holidays!" ";
Unset ($var 3);

21. Constants

The syntax format for the define () function is:

BOOL Define (String $constant _name, mixed $value [, $case _sensitive = True])

The first parameter, "Constant_name", is a required parameter, a constant name, or a marker, and the name of the constant is consistent with the variable, but be aware that it does not have a dollar sign. The second parameter, "value," is a required parameter, which is the value of the constant. The third parameter, "Case_sensitive", is an optional parameter, specifying whether it is case sensitive, set to true to be insensitive, and generally without specifying a third parameter, the value of the default third parameter is False.

$p = "PII";
Define ("PI", 3.14);
Define ($p, 3.14);

22,

System constants

(1) __file__:p hp program file name. It can help us get the current file in the physical location of the server.

(2) __line__:P HP program file line number. It can tell us the current code in the first few lines.

(3) Php_version: The version number of the current parser. It can tell us the current PHP parser version number, we can know in advance whether our PHP code can be parsed by the PHP parser.

(4) Php_os: Executes the current PHP version of the operating system name. It can tell us the name of the operating system used by the server, and we can optimize our code based on the operating system.

23,

How constants are evaluated

A, direct access

B. Using the constant function

Mixed constant (string constant_name)
eg. $area =constant ($p) * $r * $R;


24,

How to determine if a constant is defined

The defined () function helps us to determine whether a constant has been defined and its syntax is:

bool Defined (string constants_name)

It only has the parameter constant_name, refers to gets the name of the constant, returns the Boolean type True if present, otherwise returns the Boolean type false; (Note: bool means the return value type of the function is a Boolean type)

25,

Assignment operators

(1) "=": assigns the value of the right expression to the left operand. It copies the value of the right expression to the left-hand operand. In other words, the left operand is first requested for a piece of memory, and then the copied value is placed in this memory.

(2) "&": Reference assignment means that both variables point to the same data. It will allow two variables to share a piece of memory, and if the memory stored data changes, then the values of the two variables will change.

26,

Comparison operators


eg $a = 1;
$b = "1"; $a = = $b but $a!== $b

27.

Ternary operators

("?:") The ternary operator is also a comparison operator, for expressions (EXPR1)? (EXPR2):(EXPR3), if the value of EXPR1 is true, the value of this expression is expr2, otherwise EXPR3.

28. Logical Operators

29.

String Join operators

(1) Join operator (".") : It returns the string that is appended to the right argument after the left argument.

(2) Connection assignment operator (". ="): It attaches the right argument to the left argument, and the resulting concatenated value to the left argument



30.

Error control operator

Any error messages that may be generated by the expression are ignored until the @ is placed in a PHP expression, and any error messages generated by the expression are stored in the variable $php_errormsg


eg. $conn = @mysql_connect ("localhost", "username", "password");
echo "Error, the reason is:". $php _errormsg;


31,

foreach Loop statement

(1) value only, do not remove the label

 
  

(2) Remove the mark and value at the same time

 
  Value) {//Perform the task}?>
eg. $students = Array (
' I ' = ' make Fox rush ',
' + ' and ' 林平 ',
' I ' and ' Song Yang ',
' ~ ' = ' ren ying ',
' The ' and ' to ask the heavens ',
' + ' = ' let me Do ',
' ~ ' and ' dashed ',
' = ' and ' founder ',
' 2018 ' and ' Yue Qun ',
' 2019 ' and ' Ning Zhong ',
)///10 student's number and name, stored in an array

Iterate through an array using the loop structure to get the number and name
foreach ($students as $num = $v)
{
Echo $num;
echo $v;//output (print) name
echo "
";
}


32. Arrays

One-dimensional arrays

$students = Array (
' I ' = ' make Fox rush ',
' + ' and ' 林平 ',
' I ' and ' Song Yang ',
' ~ ' = ' ren ying ',
' The ' and ' to ask the heavens ',
' + ' = ' let me Do ',
' ~ ' and ' dashed ',
' = ' and ' founder ',
' 2018 ' and ' Yue Qun ',
' 2019 ' and ' Ning Zhong ',
);


Two-dimensional arrays

$students = Array (
' =>array ' (' Linghutao ', ' 59 '),
' =>array ' (' 林平 ', "44"),
' =>array ' (' Qu Yang ', ' 89 '),
' =>array ' (' Ren Ying ', ' 92 '),
' =>array ' (' to ask the Heavens ', "93"),
' =>array ' (' Any line ', ' 87 '),
' =>array ' (' dashed ', ' 58 '),
' =>array ' (' founder ', ' 74 '),
' 2018 ' =>array (' Yue Qun ', ' 91 '),
' 2019 ' =>array (' Ning Zhong ', "90"),
)////10 student's number, name, score, stored in an array

To take a value from a two-dimensional array:

foreach ($students as $key = $val)
{//Use loop structure to iterate through the array, get the study number
Echo $key; Output number
echo ":";
Loop output name and score
foreach ($val as $v)
{
Echo $v;
}
echo "
";
}

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