You should learn PHP in this posture (2)

You should learn PHP in this posture (2)

1. What are the ways to loop an array

1) foreach (capable of cyclically associating and indexing arrays and objects)

2) for (can only loop index array)

3) List and each use circular array together

$arr = ['a'=>1,'b'=>2];

while(list($key,$val) = each($arr)){

echo $key$,val


2. is_array(), is_bool, is_int(), is_integer(), is_numeric(), is_string(), is_object(), is_null, is_file, is_dir, is_readable, is_uploaded_file, is_writeable,

1) is_array() checks whether a variable is an array

2) is_file() checks whether it is a file

3) is_dir() checks whether it is a directory

4) is_uploaded_file() checks whether it is through http post

5) is_readable() checks whether it is readable

3. count()

1) Calculate the length of the array

4. array_sum(), array_product()

1) array_sum() calculates the sum of an array

2) array_product() calculates the product of the array

5. array_count_values()

1) Calculate the sum of the number of occurrences of the values ​​in the array

6. in_array() array_key_exists() array_search() key_exists()

1) in_array('xxx',$arr) judge whether a character is in the array, and return false or true

2) array_key_exists('xxx',$arr) Determine whether a key exists in this array

3) array_search('xxx',$arr) Determine whether a value is in the array and return the key

7, array_values() array_keys() array_column()

1) array_values($arr) returns the value of the array

2) array_keys() returns all the keys of the array

2) array_column($arr,'xxxx') returns the value of a certain column of the array

8. array_filter() array_walk() array_walk_recursive() array_map()

1) array_filter($arr,'function') Filter an array with a callback function

2) array_walk($arr,'function',[$param]) handles the array with a callback function, and can use another value as a parameter to pass to the function

3) array_walk_recursive($arr,'function',[$param]) uses a function recursively on an array

4) array_map($arr,funciont) applies a function to each element of the array

9, array_unique()

1) Deduplicate the array

10. array_change_key_case()

1) Convert all the key names of the array to lowercase

11. range()

1) range(0,n,step=step size) creates an array

12. array_fill() array_fill_keys()

1) array_fill(key_start,long,'xxx') fill the array with a certain value

2) array_fill_keys($arr,'xxx') Combine a certain value with the current array to generate a new array with $arr as the key and xxx as the value

13, array_flip() array_reverse()

1) array_flip() exchanges the built-up value of the array

2) array_reverse($arr,[true]) Reverse the array, if the second parameter is true, the original key of the array will be retained

14. array_pad()

1) array_pad($arr,long,xxx) fill the array to the specified length

15, array_rand() shuffle()

1) array_rand($arr,2) randomly remove several arrays

2) shuffle() shuffles the array

Application scenario: random or a value of an array

16, array_shift() array_unshift() array_push() array_pop()

1) array_shift($arr) pops a value from the head, stack

2) array_unshift($arr,[a,b,c...]) into the stack

Application scenario: simulation stack

3) array_push($arr,[a,b,c....]) inserts a value into the array from the end

4) array_pop($arr) pops a value from the tail

Application scenario: Cooperate with array_unshift to simulate queue

18. array_merge() array_merge_recursive()

1) array_merge() merges two arrays, the latter will overwrite the same value of the former key

2) array_merge_recursive() merges two arrays recursively, the latter will overwrite the same value of the former key

Application scenario: the combination of two configuration files in the framework

19. Array_multisort(), sort (), rsort (), krsort (), ksort(), asort(), arsort()

1) array_multisort($arr[0],SORT_ASC,$arr[1],SORT_DESC);

Sort multiple arrays

2) Sort array in ascending order

3) rsort array in descending order

4) krsort uses key-value pairs in descending order

5) ksort uses the key value to sort the array in ascending order

6) asort sorts the array in ascending order and maintains the index relationship

7) arsort sorts the array in descending order and maintains the index relationship

20, next prev rest end current

1) next//move the pointer in the array forward one place

2) prev//Rewind the internal pointer of the array one bit

3) rest//Point the array pointer to the first unit

4) end//Point the array pointer to the last unit

5) current//Returns the current unit in the array

21, max() min()

1) max() takes the maximum value

2) min() takes the minimum value

Reference: You should learn PHP in this posture (2)-Cloud + Community-Tencent Cloud