


Summary of PHP common functions (array part) shared version will have some errors_PHP tutorial
Function name Purpose Format Input Output Operation
Array generation and conversion:
array() generates an array array array(mixed [...]) array value or, key => value an array variable None
array_combine() generates an array, using the value of one array as the key name and the value of the other array as the value array array_combine(array $keys, array $values) $keys is the array that provides the key, and $values is the array that provides the value. Array None
range() creates an array of specified range units array range(mix $low,mix $high,[num $step]) $low minimum value, $high maximum value, $step step size Synthetic array None
compact() creates an array, including their variable names and values arr compact(mix $varname,[,mix $...]) various variables, and the array returns an array consisting of variable names as keys and variable values as values. It can also be a multi-dimensional array. It will be processed recursively without
array_fill() generates an array array with a given value array_fill(int $start, int $num, mix $value) Starting with the key of $start, $num elements, $value is the filling content Returns the completed array None
Array merging and splitting:
array_chuk() divides an array into multiple specified arrays array_chunk(arr $input,int $size[,bool $preserve_keys]) $input is the array to be operated on, $size contains several elements in each copy, $preserve_keys is Boolean, whether to preserve the keys The divided multi-dimensional array has no
array_merge() merges one or more arrays. If the keys of the elements are the same, the previous ones will be overwritten, and the sequence of indexes will not be overwritten, only arr will be automatically increased array_merge(arr $arr1[, arr $arr2,...] ) $arr1, etc. return the completed array for the operated array. None
Array comparison operations:
array_diff() Calculate the difference of arrays array array_diff(arr $arr1,arr $arr2[,...]) Input two or more arrays and compare the differences of several array element values None
array_intersect() Calculate the intersection of arrays array array_intersect(arr $arr1,arr $arr2[,...]) Input two or more arrays Compare the intersection of several array element values None
Array search and replace operation:
array_search() Search the given value from the array and return the key name mix array_search(mix $need,arr $arr[bool $stric]) $need is the search string, $arr is the target array, and $stric is true. If the matching variable type is successful, the key name will be returned. If it fails, it will return false. None
array_slice() Take out a segment arr array_slice(arr $array,int $offset[,int $length[bool $p_key]) from the array $array target array;$offset offset;$length interception length;$p_key:true Keep the key name. The key name $array target array will be reassigned by default; if $offset is non-negative, it will start from this offset. If it is a negative value, it will start from this far from the end; if $length is positive, there will be this in the sequence. Multi-unit, if not negative, the sequence ends at this far from the end. None
array_splice() Remove part of the array and replace arry with other values array_splice(arr &$input,int $offset[,int $leng[,arr $rep]]) $input is the target array, $offset is the offset, $ If leng does not exist, all elements from $offset to the end will be removed. If it is a positive value, so many units will be removed. If leng is a negative value, so many units from $offk to the end of $leng will be removed. The replaced part will replace the original array. Note that the key names in the array are not retained after replacement. If $rep is given, the original array will be replaced by the new array elements
array_sum() calculates the sum of all values in the array number array_sum(arr $array) target array returns the sum None
in_array() Finds whether a certain value exists in the array, case-sensitive bool in_array(mix $need,arr $array[,bool $str]) Searches $need in $array, if $str is true, the check type is also To match. Return true if found, false if not found None
array_key_exists() Check whether the given key name exists bool array_key_exists(mix $key, arr $serch) $key searches for the key, $serch target array returns whether it is found None
Array pointer operations:
key()
current() alias pos()
next()
prev()
end()
reset()
list() assigns the values in the array to the variable void list(mix $var1[,$var2...])=arr $array
array_shift()
array_unshift()
array_push() The array finally pushes multiple elements int array_push(arr &$array,mix $var1[,$var2...]) &$array target array,$var1.. returns 1 for success when adding the value, and 0 for If failed, directly operate on the target array
array_pop() The last element of the array pops out mix array_pop(arr &$array) &$array is the target array, returns the value of the popped element, and directly operates on the target array
Array key value operations:
shuffle() shuffles the array and retains the key names bool shuffle(arr &$array) inputs the array and returns true. The key names will not change after shuffling the order
count()
array_flip() exchanges the keys and values in the array arr array_flip(arr $trans) $trans is the operated array Returns the completed array None
array_keys() returns all the keys of the array to form an array arr array_keys(arr $input[,mix $search[,bool $str]]) If $search has a value, it will only return the key name corresponding to this value. If $str is true, , and also compare types to return an array composed of key names without
array_values() returns all the values in the array to form an array array array_values (array $input)
array_reverse() returns an array with the elements in the reverse order arr array_reverse(arr $input[,bool $key]) Input the target array, if $key is true, the original key name is retained. An array in the reverse order None
array_count_values() counts the number of occurrences of all values in the array array array_count_values(array $input) $input is the array being operated on, using the value of input as the key and the number of occurrences as the value. None
array_rand() randomly extracts one or more elements from the array, note the key name!!! mix array_range(arr $input[,int $num]) $input is the target array, $num is the number of elements extracted and returned The key of the element, if it is one, it is a key name; if there are multiple elements, these keys will be used as values to form an index array and return None
each()
array_unique() removes duplicate values from the array, first sorts the values, then only retains the first encountered key name, and then ignores the remaining key names array array_unique(arr $array) Enter the target array key name and retain it Variable returns an array with no duplicate values
Sort an array:
sort() sorts the array (from low to high), without retaining the key name bool sort(arr &$array[,int $flag]) The target array returns true if successful, false if failed. Rearranges the array elements and changes the keys at the same time. First name
rsort() sorts the array in reverse order (from high to low), without retaining the key name bool rsort(arr &$array[,int $flag]) The target array returns true if successful, false if failed. Rearranges the array elements and changes them at the same time. Key name
asort() Sort the array and keep the index relationship bool asort(arr &$array[,int $flag]) Target array Return true if successful, false if failed Sort the array and keep the original index or key
arsort() sorts the array in reverse order, maintaining the index relationship
ksort() Sorts the array by key name bool ksort(arr &$array[int $flag]) Target array Returns true if successful, false if failed Sorts the key name and retains the key-value correspondence
krsort() sorts the array in reverse order by key name
natsort() ""Natural algorithm""sorts the array, maintaining the key-value relationship" bool natsort(arr &$array) The target array returns true if successful, false if failed. Sorts the values naturally, retaining the key-value relationship
natcasesort() natural sorting, case-insensitive bool natcasesort(arr &$array) target array returns true on success, false on failure, performs natural sorting of values without case sensitivity, and maintains key-value correspondence
Excerpted from Battlefield Diary_LAMP Band of Brothers

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.
