PHP Array Usage Summary, PHP array Summary
In PHP, arrays are divided into two categories: indexed arrays and associative arrays. They can be used alone or in combination.
1. One-dimensional arrays
The definition of one-dimensional array is also very simple, commonly used in the following two ways:
1.1 Direct Assignment
1:
3: $dwqs [1] = "My blog:";
5: $DWQS [3] = "Program enthusiast:";
7: $dwqs [5] = "Welcome to join";
1.2 Array () build arrays
1:
3: ?>
2. Multidimensional arrays
Take an associative array as an example
1:
3: "numbered"array,
Array ("Independent blog","CSDN","blog Park"),
Array ("www.ido321.com","blog.csdn.net/u011043843","www.cnblogs.com/ido321")
Second, array traversalin PHP, there are three commonly used array traversal methods:1. For Loop1:
3: echo"$dwqs [i]
";
2. foreach statement
1: //First way
3:foreach as $value) {
;
6:
8:
: echo $key." = ". $value;
3. While loop
1:
3: echo $key.":". $value;
Third, partial array-related functions (using the print_r () function to output array contents)
PHP's array functionality is very powerful and is one of the most commonly used data types. Its processing function also has a strong, efficient characteristics.
1. Key/value operation function of array
1.1 Function Array_values (): Returns the value of all elements in the array. The array name is passed in, the key name is not preserved, and the returned array is re-indexed starting at 0.
1:
"www.ido321.com","program enthusiasts""QQ Group: 259280570");
4: print_r (Array_values ($dwqs 2));
"Www.ido321.com", "program enthusiast" = ">" "QQ Group: 259280570"); <= "" Font= "" >
7:
1.2 Function Array_keys (): Returns the name of the key in the array.
1:
3:
5: print_r (array_kays ($dqws,' ID '));
1.3 function In_array (): Detects if a value exists in the array
1:
3://output: Presence
5: echo"existence";
7:Else{
9: }
2. Number and uniqueness of arrays2.1 function count (): counts the number of elements in an array or the number of attributes in an object1:
3: ?>
2.2 Function Array_unique (): Delete duplicate values in array, return array key name remains unchanged
1:
' php ',' B ' 'mysql ',' C '' Linux ',' d 'php ';
4: print_r (Array_unique ($a));
2.3 Function Array_count_values (): Counts the number of occurrences of all values in the array, the returned array takes the values in the original array as the key name, and the key value is the number of occurrences of the element in the original array
1:
3: print_r (array_count_values ($a));
3. Array sorting
Source: http://www.ido321.com/596.html
How do arrays in PHP classes work?
You $a the private; defined as public $a, you can use $obj->a directly.
$obj->a[' key ' is the value you want to access.
Usage of PHP arrays
First of all, you are really a different kind of writing, now PHP comparison of general curly brace notation
(1) For weak language PHP, do not need to be like rigorous language initialization, when used automatically initialized. So, after declaring the array, we can use it. And sometimes there is no need to declare, such as direct write $i = 1.25; If you want to make an error in a rigorous language, PHP can use it.
(2) The array default index is starting from 0 and then adding 1. Count ($arr) is the number of array elements. Assuming n is the number of elements in the current array, then $arr[n-1] is the largest element of the index. Adding $arr[n] is the equivalent of adding an element after the array. Can actually write $arr[] = $ss, the effect is the same.
(3) algorithm thinking problem, meaning that a natural number can be smaller than its small prime numbers divisible, then it is not prime.
(4) The procedure is not wrong ....
http://www.bkjia.com/PHPjc/878338.html www.bkjia.com true http://www.bkjia.com/PHPjc/878338.html techarticle PHP array using summary, PHP array Summary in PHP, the array is divided into two categories: indexed arrays and associative arrays. They can be used alone or in combination. 1, one-dimensional array of one-dimensional arrays ...