PHP Basics for Beginners PHP Summary

Source: Internet
Author: User
Tags php basics
For PHP Beginners Some basic knowledge, can also be counted as some experience accumulated bar, there is a need for friends, can refer to the next.

PHP Basics

First, phpphp is an embedded language used in combination with HTML. 1, PHP tag default mark short Mark , need to open the Short_open_tag option in php.ini short mark and other tags do not promote the use of

2, the keyword is not case-sensitive, the user-defined class name and function name are not case-sensitive, variable names are case-sensitive

3. Output Boolean print (parameter) returns a Boolean value void Echo (parameter) No return value Echo's efficiency is a little higher.

Second, the data type 1, compares two floating-point number The usual method is moves several decimal place first, then transforms to the integer data then compares.

2, double quotation mark delimiter string support variable name resolution, single quote delimiter string does not support variable name resolution. $name = "Zhang San"; " $name "= Zhang San | | ' $name ' and $name | | "Mr. $name" and the Empty | | "{$name} Mr." = Mr. Zhang San | | "Mr. ${name}" and Mr. Zhang San

3. How the string is defined: single quotes, double quotes, and Heredoc (<<<>< p=""><>

4. The object type must be declared explicitly. Class is defined with the keyword class, using the keyword new to generate an instance of the class, using the notation class, to access the properties and methods in the class Car{public $cololr; function beep () {}} $mycar = new car; $mycar->color= ' red '; $mycar->beep ();

5, PHP is a weak language type, the type of the variable will be based on the given value of the self-determination, and often in the variable declaration at the same time the variable value assignment.

6. When a data type is cast, only the type name you want is written in parentheses before the variable.

Three, constants and variables

1, define constant define ("constant name", expression or value) The constant name suggests all caps, but is not required to use constants directly using the defined constant name, do not need to add "$" predefined constants before the constant name: _file_ the current PHP program file name _line_ the current PHP program in the number of lines ( Where do you mean?

2, the variable does not need explicit declaration, when the variable is assigned the initial value of the variable is declared. If the variable is not set to the initial value, its initial value is null.

3, the assignment of variables: value assignment and reference assignment value. such as $a=& $b; That is, B has pointed to a storage location, after the reference assignment, a also points to the storage location, when the destruction of a or B will not have any impact on the other, but if one of the values change, then the other will make the same change.

4, access to predefined variables using super global variables, a total of 9 super global variables

5. Local variables: variables defined within a function can only use global variables within a function: variables defined outside of the function can only be used outside of the function to use global variables within a function, you need to declare the variable with global in the function, or use the Super global variable array &globals["variable name"] In PHP, only functions can provide local scopes. The hyper-global variable $globals contains all the characteristics of a variable static variable: It is initialized only the first time it is called, the function is not destroyed after it is finished, and the variable retains its original value the next time it is used. Static variables can only be defined and used within a function. mutable variable: The name of the variable is also used as a variable. $a =b; $b =c;$ $a = $b =c; External variables: Data that can be passed with get is up to 256 bytes, using post up to 2MB

Iv. Process Control (differs from other languages such as Java only) 1, interactive format (colon syntax) is not recommended, the classic is more intuitive

2. foreach (): This syntax is the first format specifically designed for the array foreach (Target_array as $value) statement second format foreach (Target_array as $key + $value) Statement

3. Break number: The number of layers of the structure to jump CONTIUE number: The number of layers of the structure to be jumped out

4. The exit statement can end the execution of the current entire script and is typically used for error checking. Exit Exit ("Error reason");d ie () is the alias of exit $conn =mysql_connect ("localhost", "root", "") or Die ("Unable to connect to MySQL server");

The only difference between an array 1, an associative array, and a numeric index array is the type of the index.

2, numeric index array initialization: Directly array element assignment Array () function if the arrays do not exist, then the array element is assigned a value can be created at the same time if the array elements are sequentially numbered, then the range () function range () has 3 parameters when initializing arrays. , the first parameter specifies the initial value, the second parameter specifies the terminating value, and the third parameter is optional to specify the step size

3. Associative array initialization: assigning an array () function directly to a set of elements

4. Array-related operator + Union $a + $b after the attachment to $ A, but any element that conflicts with the index value will not be added = = equals $a = = $b if $ A and $b contain the same element, return True (index value and element must be the same) except in order, the others must be exactly the same! = < > is not equal to = = = True if $ A and $b contain the same elements in the same order, the return value (index values and elements must be the same) must be exactly identical!== not identical

5, the array of sort Boolean sort () is arranged in numbers and alphabetical order will give the new index value, the original index value is deleted void Asort () sorted in ascending order after sorting the array to retain the original index relationship integer ksort () Arrange by index value ascending usort (array, method name) sorted by user-defined method array_multisort () sorts multiple arrays at once Natsort () sorts them in natural order, retains the original index relationship natcasesort () natural sort after sorting, Case insensitive

6, the inverse of the array rsort () arrays are sorted in descending order Arsort () Krsort ()

7, the array is reordered Boolean shuffle () array is randomly arranged array array_reverse () to invert the elements in arrays Array_flip () to redeem an index in an array with its element value

8. Array traversal current () Gets the value of the element in the array that the pointer refers to next () moves the pointer of the array back one bit, returning the element value of the element to which the pointer points prev () moves the array pointer forward one bit, returning the element value of the element that the pointer points to after the move, reset () The pointer is set back to the starting position of the array end () moves the pointer to the last element of the array each () returns the index/element value pair pointed to by the current pointer in the array, and moves the array pointer backward one returns an array of 4 elements with an index of 0,key. 1,valuekey () returns the index value pointed to by the current pointer of the array array_walk () is processed in the same way as each element in the array array_reduce () applies the custom function to each element of the arrays sequentially 9, the other array operation function list () Extracts multiple values at once from an array and assigns values to multiple variables count ()/sizeof () computes the number of elements in the array 1 2 3 4 Next last

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