Home > Article > Backend Development > PHP array functions
We always use some PHP-related functions for processing in daily development. Doing so can solve problems more effectively and simplify problems, so it is still necessary to master these functions.
prev($array name)//Move the array pointer forward to one position, opposite to next().
next()- Set the internal pointer to the next element in the array and output it.
current()- Returns the value of the current element in the array.
end()- Point the internal pointer to the last element in the array and output
reset()- Point the internal pointer to the first element in the array and output it.
each()- Returns the key name and key value of the current element and moves the internal pointer forward.
array_values($array name) takes out the values of the array elements in the array to form a new index array and returns it.
array_keys($array name); Extract the key names in the array to construct a new index array, and return
array_flip($array) Exchange the key names and key values of the array to form A new associative array, returned.
in_array($value,$array name) Query whether $value exists in the array. If it exists, return true, if it does not exist, return false;
array_search($value,$array name ); If the value exists in the array, the key name is returned. If it does not exist, false is returned;
array_key_exists($key,$array name) detects whether the key name exists in the array. If it exists, it returns true. If it does not exist, it returns true. Return false;
range($star,$end);Returns a new index array composed of integer arrays from start to end
array_reverse($array name)Return the array in the array The order of the elements is reversed.
array_rand($array name,$num) randomly takes out num keys to form a new index array and returns
shuffle($array name) to change the array element value The positions are scrambled
array_merge($arr1,$arr2); Merge the two arrays. If there are the same key names, remove them
array_sum($array name) Merge the array elements in the array Addition and summation
array_product($array name);Multiply and product the array elements
Array and string related functions
explode( "Separator", string) splits the string according to the separator and returns an array.
implode("connector",$array name); Connect the array elements in the array with a connector and return a string
Splitting and filling of arrays
array_chunk($array name,$num) divides the array by the number of num and returns a two-dimensional array
array_pad($array name,$length,string) ; When length > count($array name), the excess number of elements will be filled with strings.
array_fill($start,$length,"string") start is the starting key name, length is the number of array elements,
array_shift() function is used to delete elements in the array The first element and returns the removed element.
These array functions are often used in our daily development. If you master them, daily development will be no problem at all.
Related content:
Detailed explanation of php array function
php array function implements editing of association tables
Definition and usage of php array function array_push()
The above is the detailed content of PHP array functions. For more information, please follow other related articles on the PHP Chinese website!