An array of PHP

Source: Internet
Author: User
Tags array definition scalar
This article introduces the contents of the PHP array, has a certain reference value, now share to everyone, the need for friends can refer to

Array
Declaration and use of arrays
Contrast
Scalar: A standard quantity that only one value is stored inside a
Array: A combination of data that can hold multiple values
Classification
Indexed array
Associative arrays
Statement
Direct declaration
$array =array (1,2,3,4); Indexed array
$array =array (' name ' = ' Zhansan ', ' sex ' = ' nan '); associative array
Declaring an indexed array
$array [0]=1
declaring associative arrays
$array [' name ']= ' Zhangsan '
Keys (key)
Subscript: The corresponding representation in the data, which is the 0 and name written above
VALUES (value)
The data for the subscript in the array
Elements
The combination of keys and values is collectively referred to as an element
Use
Array name [subscript]
Characteristics
1, you can use [] to declare, manipulate arrays can also use {} to declare, manipulate arrays, but recommended to use []
2, the declaration of the array can be used without subscript only [], which will default to the index array, the subscript starts from zero, and then increments
3, use [] alone, without specifying the subscript, the value of the index will be the largest occurrence of subscript +1
4. When declaring an array, the table below the index array can be discontinuous
5, the array subscript can be negative, but not much significance, not recommended to use
6, if the label has a duplicate, then the back will overwrite the previous (Index and association are the same)
7. If you declare an associative array without quotation marks to include the subscript, it will be treated as a constant
8, associative arrays and indexed arrays can exist in the same array at the same time, mixed arrays are associative arrays
9. The associative subscript of an array does not affect the arrangement rules of index subscript
To delete an element in an array
Unset () free directly in memory
Reassign value to NULL, value is set to NULL
Attention
After using unset to release the elements in the array, the subscript is also deleted, and when the array element is declared again, the maximum value from the occurrence of the bidding clubs is not written down +1
Multidimensional arrays
Dimension, which is to put the array inside the array (can be associative arrays can also be indexed arrays)
Traversal of an array
For
Only the indexed array can be traversed, and the subscript of the array must be contiguous.
Foreach
Format
foreach (array as custom) a variable for storing subscript = custom value for storing value) {}
Attention
The number of elements in the array, and how many times (automatic) is traversed
Whether it's an indexed array or an associative array
Pointer functions
Key ()
Gets the key of the current element
Current ()
Gets the value of the current element
Next ()
The pointer moves down and returns a false when the next pointer corresponds to the value to the end
Prev ()
The pointer moves up and returns the value corresponding to the previous pointer
End ()
Moves to the last and returns the value of the element
Reset ()
Move to the first and return the value corresponding to the element
Hyper-Global Array
Description
Can be used in any place
$_get
Receive HTTP protocol the value passed in a GET request $_get can get the value of form get method, the parameter of a connection band, the parameter in action of form can get
$_post
The Post method is usually used to submit a form when the received HTTP protocol is submitted as a POST request.
$_request
It is not recommended to receive data from $_get and $_post and $_cookie.
$_cookie
Array of variables that receive the HttpCookie method passed to the script
$_session
An array of session variables available in the current script
$_files
Receive File upload information
$_globals
Receive all the variables in the script
$_server
Some variables about the server
Http_host User's host
Http_user_agent what browser the user accesses
Server_Name server name
SERVER_ADDR Server IP Address
REMOTE_ADDR Browse the User IP address of the current script
Address of the Document_root root directory
Server_port Port number
Script_name the path of the current script
Function
How to learn Functions
Know what this parameter is for.
What are the parameters?
What is the return value type
Pseudo-type in parameters
Mixed shows that a parameter can receive many different types
Number indicates that a parameter is an int or float
Callback callback function
void if the return value is not used as a return type, indicating that the function does not accept any arguments as a parameter
Note [] indicates an optional parameter
return value of the function
What is the return value type
Stacks and queues
Stack
The process of pressing bullets, advanced after out. We are commonly referred to as stacks, press-in data called into the stack, pop-up data called out of the stack. Features, advanced after out
Queue
Station queuing process, FIFO
Declaration and use of arrays
Contrast
Scalar: A standard quantity that only one value is stored inside a
Array: A combination of data that can hold multiple values
Classification
Indexed array
Associative arrays
Statement
Direct declaration
$array =array (1,2,3,4); Indexed array
$array =array (' name ' = ' Zhansan ', ' sex ' = ' nan '); associative array
Declaring an indexed array
$array [0]=1
declaring associative arrays
$array [' name ']= ' Zhangsan '
Keys (key)
Subscript: The corresponding representation in the data, which is the 0 and name written above
VALUES (value)
The data for the subscript in the array
Elements
The combination of keys and values is collectively referred to as an element
Use
Array name [subscript]
Characteristics
1, you can use [] to declare, manipulate arrays can also use {} to declare, manipulate arrays, but recommended to use []
2, the declaration of the array can be used without subscript only [], which will default to the index array, the subscript starts from zero, and then increments
3, use [] alone, without specifying the subscript, the value of the index will be the largest occurrence of subscript +1
4. When declaring an array, the table below the index array can be discontinuous
5, the array subscript can be negative, but not much significance, not recommended to use
6, if the label has a duplicate, then the back will overwrite the previous (Index and association are the same)
7. If you declare an associative array without quotation marks to include the subscript, it will be treated as a constant
8, associative arrays and indexed arrays can exist in the same array at the same time, mixed arrays are associative arrays
9. The associative subscript of an array does not affect the arrangement rules of index subscript
To delete an element in an array
Unset () free directly in memory
Reassign value to NULL, value is set to NULL
Attention
After using unset to release the elements in the array, the subscript is also deleted, and when the array element is declared again, the maximum value from the occurrence of the bidding clubs is not written down +1
Multidimensional arrays
Dimension, which is to put the array inside the array (can be associative arrays can also be indexed arrays)
Traversal of an array
For
Only the indexed array can be traversed, and the subscript of the array must be contiguous.
Foreach
Format
foreach (array as custom) a variable for storing subscript = custom value for storing value) {}
Attention
The number of elements in the array, and how many times (automatic) is traversed
Whether it's an indexed array or an associative array
Pointer functions
Key ()
Gets the key of the current element
Current ()
Gets the value of the current element
Next ()
The pointer moves down and returns a false when the next pointer corresponds to the value to the end
Prev ()
The pointer moves up and returns the value corresponding to the previous pointer
End ()
Moves to the last and returns the value of the element
Reset ()
Move to the first and return the value corresponding to the element
Hyper-Global Array
Description
Can be used in any place
$_get
Receive HTTP protocol the value passed in a GET request $_get can get the value of form get method, the parameter of a connection band, the parameter in action of form can get
$_post
The Post method is usually used to submit a form when the received HTTP protocol is submitted as a POST request.
$_request
It is not recommended to receive data from $_get and $_post and $_cookie.
$_cookie
Array of variables that receive the HttpCookie method passed to the script
$_session
An array of session variables available in the current script
$_files
Receive File upload information
$_globals
Receive all the variables in the script
$_server
Some variables about the server
Http_host User's host
Http_user_agent what browser the user accesses
Server_Name server name
SERVER_ADDR Server IP Address
REMOTE_ADDR Browse the User IP address of the current script
Address of the Document_root root directory
Server_port Port number
Script_name the path of the current script
Function
How to learn Functions
Know what this parameter is for.
What are the parameters?
What is the return value type
Pseudo-type in parameters
Mixed shows that a parameter can receive many different types
Number indicates that a parameter is an int or float
Callback callback function
void if the return value is not used as a return type, indicating that the function does not accept any arguments as a parameter
Note [] indicates an optional parameter
return value of the function
What is the return value type
Stacks and queues
Stack
The process of pressing bullets, advanced after out. We are commonly referred to as stacks, press-in data called into the stack, pop-up data called out of the stack. Features, advanced after out
Queue
Station queuing process, FIFO

Related recommendations:

Array processing for PHP

An explanation of the array definition and traversal of PHP

Related Article

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.