You should learn PHP in this pose (2)

1. What are the ways to loop an array?

1) foreach (able to loop over associative and indexed arrays and objects)

2) for (can only loop through indexed arrays)

3) List and each use loop 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 if a variable is an array

2) is_file() checks if it is a file

3) is_dir() checks if it is a directory

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

5) is_readable() checks if 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) determines whether a character is in the array and returns false or true

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

3) array_search('xxx', $arr) determines whether a value is in the array and returns 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 column of the array

8、array_filter() array_walk() array_walk_recursive() array_map()

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

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

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

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

9、array_unique()

1) Deduplication operation on the array

10、array_change_key_case()

1) Convert all key names of the array to lowercase

11、range()

1) range(0,n,step=step) to create an array

12、array_fill() array_fill_keys()

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

2) array_fill_keys($arr,'xxx') Combine a 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() swaps the built and value of the array

2) array_reverse($arr,[true]) reverses the array, if the second parameter is true it will keep the original key of the array

14、array_pad()

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

15、array_rand() shuffle()

1) array_rand($arr,2) randomly removes 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...]) onto the stack

Application Scenario: Simulation Stack

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

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

Application scenario: simulate queue with array_unshift

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 merger 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 ascending order

3) rsort array descending

4) krsort uses key-value pair arrays 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 forward one place in the array

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

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324479294&siteId=291194637