Home > Backend Development > PHP Tutorial > PHP study notes (1) array

PHP study notes (1) array

WBOY
Release: 2016-07-29 08:51:24
Original
1134 people have browsed it

Methods to initialize arrays: unified initialization or item-by-item initialization.

Methods to traverse the array:

1. FOR loop

2. DO...WHILE statement

3. WHILE statement

4. foreach

<span>foreach</span>(<span>$arr</span><span>as</span><span>$key</span>=><span>$val</span><span>)
    {
        </span><span>echo</span><span>$key</span>."=".<span>$val</span>."<br/>"<span>;
    }</span>
Copy after login

The key value in the array can be an integer or is a string.

  Arrays can store any data type.

 Understand content: array operators.

Array sorting problem:

Internal sorting:

1. Bubble sort

2. Selection sort

3. Insertion sort

4. Quick sort

External sorting:

About function parameters The problem:

When the formal parameter takes the address character: it means that the address is passed, that is, the address in the original array is passed, and the original value will be changed.

When the formal parameter does not take the address character: the default transfer is value transfer, not address transfer, that is, a brand new array transfer, and the value of the original array will not be changed.

  Other knowledge:

Commonly used functions:

1. count

<span>count</span>(<span>$arr</span>);  <span>//</span><span>获取数组的长度</span>
Copy after login

2. is_array: Determine whether it is an array.

 3. print_r: Displays easy-to-understand information about a variable. If given a string, integer or float, the variable value itself will be printed. If array is given, keys and elements will be displayed in a certain format. object is similar to an array.

  4. var_dump: Returns the type and value of the expression.

  5. explode: Use one string to split another string.

  6. Round: Round floating point numbers to a specified number of digits.

 7. Unset: Destroy an element or a variable.

After a variable is destroyed in the array, the array will not be automatically reorganized, and the data corresponding to the key value in the array is undetermined

8. How to turn off notice level prompts in PHP:

1. Modify the php.ini file to: error_reporting = E_ALL & ~E_NOTICE

  2. Add code to the page where you want to disable error prompts: error_reporting(E_ALL ^ ​​E_NOTICE);

The above introduces the PHP study notes (1) array, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template