Home  >  Article  >  Backend Development  >  [PHP Learning] A large collection of common PHP functions that are essential for beginners

[PHP Learning] A large collection of common PHP functions that are essential for beginners

little bottle
little bottleforward
2019-04-18 16:50:293409browse

This article is a collection of common PHP functions collected by the editor. It is very complete. I will share it with everyone. A must-have PHP function dictionary for novices, so hurry up and collect it!

php usleep() function delays code execution for a number of microseconds.
The unpack() function unpacks data from a binary string.
The uniqid() function generates a unique ID based on the current time in microseconds.
time_sleep_until() function delays code execution until the specified time.
The time_nanosleep() function delays code execution for a number of seconds and nanoseconds.
sleep() function delays code execution for a few seconds.
show_source() function performs syntax highlighting on files.
strip_whitespace() function returns the source code file with PHP comments and whitespace characters removed.
pack() function loads data into a binary string.
ignore_user_abort() function sets whether disconnecting from the client will terminate the execution of the script.
highlight_string() function performs syntax highlighting on strings.
highlight_file() function performs syntax highlighting on files.
get_browser() function returns the performance of the user's browser.
exit() function outputs a message and exits the current script.
eval() function evaluates string according to PHP code.
die() function outputs a message and exits the current script.
defined() function checks whether a constant exists.
define() function defines a constant.
constant() function returns the value of a constant.
The connection_status() function returns the current connection status.
The connection_aborted() function checks whether the client is disconnected.
zip_read() function reads the next file in the opened zip archive.
zip_open() function opens a ZIP file for reading.
zip_entry_read() function gets the contents from an open zip archive entry.
zip_entry_open() function opens a ZIP archive entry for reading.
zip_entry_name() function returns the name of the zip archive entry.
zip_entry_filesize() function returns the original size of the zip archive entry (before compression).
zip_entry_compressionmethod() function returns the compression method of the zip archive entry.
zip_entry_compressedsize() function returns the compressed file size of the zip archive entry.
zip_entry_close() function closes the zip archive file opened by zip_entry_open() function.
zip_close() function closes the zip archive file opened by zip_open() function.
xml_set_unparsed_entity_decl_handler() function specifies the function to be called when an unresolved entity name (NDATA) declaration is encountered.
xml_set_processing_instruction_handler() function specifies the function to be called when the parser finds a processing instruction in the XML document.
xml_set_object() function allows the use of XML parsers in objects.
xml_set_notation_decl_handler() function specifies the function that is called when the parser finds a symbol declaration in the XML document.
xml_set_external_entity_ref_handler() function specifies the function that is called when the parser finds an external entity in the XML document.
xml_set_element_handler() function establishes the starting and ending element handlers.
xml_set_default_handler() function establishes the default data handler for the XML parser.
xml_set_character_data_handler() function creates a character data handler.
xml_parser_set_option() function sets options for the XML parser.
xml_parser_get_option() function gets option setting information from the XML parser.
xml_parser_free() function frees the XML parser.
xml_parser_create() function creates an XML parser.
xml_parser_create_ns() function creates an XML parser with namespace support.
xml_parse_into_struct() function parses XML data into an array.
xml_parse() function parses XML documents.
xml_get_error_code() function gets the XML parser error code.
xml_get_current_line_number() function gets the current line number of the XML parser.
xml_get_current_column_number() function gets the current column number of the XML parser.
xml_get_current_byte_index() function gets the current byte index of the XML parser.
xml_error_string() function gets the error description of the XML parser.
utf8_encode() function encodes ISO-8859-1 string to UTF-8.
utf8_decode() function decodes UTF-8 string to ISO-8859-1.
wordwrap() function wraps the string according to the specified length.
vsprintf() function writes the formatted string into a variable.
vprintf() function outputs a formatted string.
vfprintf() function writes the formatted string to the specified output stream.
ucwords() function converts the first character of each word in the string to uppercase.
ucfirst() function converts the first character in a string to uppercase.
trim() function removes whitespace characters and other predefined characters from both ends of a string.
substr_replace() function replaces part of a string with another string.
substr_count() function counts the number of times a substring appears in a string.
substr_compare() function compares two strings starting from the specified length.
The substr() function returns a part of a string.
strtr() function converts specific characters in a string.
strtoupper() function converts a string to uppercase.
strtolower() function converts a string to lowercase.
strtok() function splits a string into smaller strings.
The strstr() function searches for the first occurrence of one string within another string.
strspn() function returns the number of specific characters contained in a string.
strrpos() function finds the last occurrence of a string in another string.
strripos() function finds the last occurrence of a string within another string.
strrev() function reverses a string.
strrchr() function finds the last occurrence of a string in another string and returns all characters from that position to the end of the string.
strpos() function returns the position of the first occurrence of a string in another string.
strpbrk() function searches for any one of the specified characters in a string.
strncmp() function compares two strings.
strncasecmp() function compares two strings.
The strnatcmp() function uses a "natural" algorithm to compare two strings.
strnatcasecmp() function uses a "natural" algorithm to compare two strings.
strlen() function returns the length of the string.
stristr() function finds the first occurrence of a string in another string.
stripos() function returns the position of the first occurrence of a string in another string.
The stripslashes() function removes backslashes added by the addslashes() function.
stripcslashes() function removes backslashes added by addcslashes() function.
strip_tags() function strips HTML, XML and PHP tags.
strcspn() function returns the number of characters searched in the string before any specified character is found.
strcoll() function compares two strings.
strcmp() function compares two strings.
strchr() function searches for the first occurrence of a string in another string.
strcasecmp() function compares two strings.
str_word_count() function counts the number of words in a string.
str_split() function splits a string into an array.
str_shuffle() function randomly shuffles all characters in a string.
str_rot13() function performs ROT13 encoding on a string.
str_replace() function uses a string to replace other characters in a string.
str_repeat() function repeats a string a specified number of times.
str_pad() function pads the string to the specified length.
str_ireplace() function uses a string to replace other characters in a string.
sscanf() function parses input from a string according to the specified format.
sprintf() function writes the formatted string into a variable.
soundex() function calculates the soundex key of a string.
similar_text() function counts the number of matching characters in two strings.
The sha1_file() function calculates the SHA-1 hash of a file.
The sha1() function calculates the SHA-1 hash of a string.
setlocale() function sets regional information (regional information).
rtrim() P
rtrim() function
PHP String function
quotemeta() function adds a backslash before some predefined characters in the string.
quoted_printable_decode() function decodes the quoted-printable encoded string and returns an 8-bit string.
The printf() function outputs a formatted string.
print() function outputs one or more strings.
parse_str() function parses the query string into variables.
ord() function returns the ASCII value of the first character of a string.
number_format() function formats numbers by thousands grouping.
nl2br() function inserts an HTML newline character (
) before each new line (\n) in a string.
nl_langinfo() function returns the specified local information.
The money_format() function formats a string into a currency string.
metaphone() function calculates the metaphone key of a string.
md5_file() function calculates the MD5 hash of a file.
md5() function calculates the MD5 hash of a string.
ltrim() function removes spaces or other predefined characters from the left side of a string.
The localeconv() function returns an array containing local number and currency information formats.
levenshtein() function returns the Levenshtein distance between two strings.
The join() function combines array elements into a string.
implode() function combines array elements into a string.
htmlspecialchars() function converts some predefined characters into HTML entities.
html_entity_decode()
chars_decode() function
PHP String function
htmlentities() function converts characters into HTML entities.
html_entity_decode() function converts HTML entities into characters.
hebrevc() function converts Hebrew text from right-to-left flow to left-to-right flow. It also converts newlines (\n) to
.
hebrev() function converts Hebrew text from right-to-left flow to left-to-right flow.
The get_html_translation_table() function returns the translation table used by the htmlentities() and htmlspecialchars() functions.
fprintf() function writes a formatted string to the specified output stream (for example: file or database).
explode() function splits a string into an array.
echo() function outputs one or more strings.
The crypt() function returns a string encrypted using DES, Blowfish, or MD5.
The crc32() function computes the crc32 polynomial of a string.
The count_chars() function returns information about the characters used in the string.
convert_uuencode() function uses the uuencode algorithm to encode a string.
convert_uudecode() function decodes uuencode-encoded strings.
convert_cyr_string() function converts characters from one Cyrillic character to another.
chunk_split() function splits a string into a series of smaller parts.
chr() function returns a character from a specified ASCII value.
chop() function removes whitespace characters or other predefined characters starting from the end of the string.
bin2hex() function converts a string of ASCII characters into a hexadecimal value.
addslashes() function adds a backslash before the specified predefined characters.
addcslashes() function adds a backslash before the specified character.
The xpath() function runs an XPath query against an XML document.
simplexml_load_string() function loads an XML string into an object.
simplexml_load_file() function loads an XML document into an object.
simplexml_import_dom() function converts DOM nodes into SimpleXMLElement objects.
registerXPathNamespace() function creates a namespace context for the next XPath query.
getNamespace() function gets the namespace used in the XML document.
getName() function gets the name of an XML element from a SimpleXMLElement object.
The getDocNamespaces() function returns the namespaces declared in the XML document from a SimpleXMLElement object.
children() function gets the child nodes of the specified node.
The attributes() function gets the attributes of a SimpleXML element.
The asXML() function returns an XML document from a SimpleXMLElement object as a string.
addChild() function adds a child node to the specified XML node.
addAttribute() function adds an attribute to the SimpleXML element.
__construct() function creates a new SimpleXMLElement object.
The mysql_unbuffered_query() function sends a SQL query to MySQL (without getting/caching the results).
mysql_thread_id() function returns the ID of the current thread.
The mysql_stat() function returns the current system status of the MySQL server.
The mysql_select_db() function sets the active MySQL database.
mysql_result() function returns the value of a field in the result set.
mysql_real_escape_string() function escapes special characters in strings used in SQL statements.
The mysql_query() function executes a MySQL query.
mysql_ping() function Pings a server connection, and reconnects if there is no connection.
The mysql_pconnect() function opens a persistent connection to the MySQL server.
mysql_num_rows() function returns the number of rows in the result set.
mysql_num_fields() function returns the number of fields in the result set.
mysql_list_processes() function lists MySQL processes.
mysql_list_dbs() function lists all databases in the MySQL server.
mysql_insert_id() function returns the ID generated by the previous INSERT operation.
mysql_info() function returns the information of the latest query.
The mysql_get_server_info() function returns the MySQL server information.
The mysql_get_proto_info() function returns MySQL protocol information.
The mysql_get_host_info() function returns the MySQL host information.
mysql_get_client_info() function returns MySQL client information.
mysql_free_result() function releases the result memory.
mysql_field_type() function returns the type of the specified field in the result set.
mysql_field_table() function returns the table name where the specified field is located.
The mysql_field_seek() function sets the pointer in the result set to the specified field offset.
mysql_field_name() function gets the field name of the specified field in the result.
mysql_field_len() function returns the length of the specified field.
The mysql_field_flags() function obtains the flags associated with the specified field from the result.
mysql_fetch_row() function fetches a row from the result set as a numeric array.
mysql_fetch_object() function obtains a row as an object from the result set (record set).
mysql_fetch_lengths() function gets the length of the content of each field in a row.
The mysql_fetch_field() function obtains column information from the result set and returns it as an object.
The mysql_fetch_assoc() function fetches a row from the result set as an associative array.
The mysql_fetch_array() function fetches a row from the result set as an associative array, a numeric array, or both. The mysql_error() function returns the text error message generated by the previous MySQL operation.
The mysql_errno() function returns the numeric code of the error message in the previous MySQL operation.
mysql_db_name() function obtains the database name returned by the mysql_list_dbs() call.
mysql_data_seek() function moves the pointer of the internal result.
The mysql_connect() function opens a non-persistent MySQL connection.
mysql_close() function closes non-persistent MySQL connections.
The mysql_client_encoding() function returns the name of the character set of the current connection.
mysql_affected_rows() function returns the number of record rows affected by the previous MySQL operation.
tanh() function returns the hyperbolic tangent.
tan() function returns tangent.
srand() function seeds the random number generator.
sqrt() function returns the square root of a number.
The sinh() function returns the hyperbolic sine of a number.
sin() function returns the sine of a number.
The round() function rounds floating point numbers.
rand() function returns a random integer.
rad2deg() function converts radians to degrees.
pow() function returns x raised to the power of y.
pi() function returns the value of pi.
octdec() function converts octal to decimal.
mt_srand() Seeds the Mersenne Twister random number generator.
mt_rand() returns a random integer using the Mersenne Twister algorithm.
mt_getrandmax() Displays the maximum possible value of a random number.
min() returns the minimum value. max() returns the maximum value.
log1p() to return log(1 x), which can be calculated accurately even when the value of x is close to zero.
log10() Base 10 logarithm. log() returns the natural logarithm.
lcg_value() Combined linear congruential generator.
is_nan() determines whether it is a legal value. is_infinite() determines whether it is infinite.
is_finite() function determines whether it is a finite value.
hypot() function calculates the length of the hypotenuse of a right triangle.
hexdec() function converts hexadecimal to decimal.
fmod() function displays the largest possible value of a random number.
fmod() function returns the floating point remainder of division.
The floor() function rounds down to the nearest integer.
expm1() function returns exp(x) - 1, which can be calculated accurately even when the value of number is close to zero.
exp() function calculates the exponent of e.
deg2rad() function converts angles to radians.
decoct() function converts decimal to octal.
dechex() function converts decimal to hexadecimal.
The decbin() function converts decimal to binary.
cosh() function returns the hyperbolic cosine of a number.
cos() function returns the cosine of a number.
ceil() function rounds up to the nearest integer.
bindec() function converts binary to decimal.
base_convert() function converts numbers between arbitrary bases.
atanh() function returns the inverse hyperbolic tangent of an angle.
atan() and atan2() and atan2() functions
PHP Math function
asinh() function returns the inverse hyperbolic sine of a number.
The asin() function returns the arcsine of different values. The returned result is a radians value between -PI/2 and PI/2.
acosh() function returns the inverse hyperbolic cosine of a number.
acos() function returns the arc cosine of a number.
abs() function returns the absolute value of a number.
The mail() function allows you to send an email directly from a script.
The libxml_use_internal_errors() function disables standard libxml errors and enables user error handling.
The libxml_get_last_error() function gets the last error from the libxml error buffer.
The libxml_get_errors() function gets errors from the libxml error buffer.
libxml_clear_errors() function clears the libxml error buffer.
The setrawcookie() function does not URL encode the cookie value and sends an HTTP cookie.
The setcookie() function sends an HTTP cookie to the client.
headers_sent() function checks if/where HTTP headers are sent.
headers_list() function returns a list of sent (or to be sent) response headers.
The header() function sends raw HTTP headers to the client.
The ftp_systype() function returns the system type identifier of the remote FTP server.
The ftp_ssl_connect() function opens a secure SSL-FTP connection.
ftp_size() function returns the size of the specified file.
The ftp_site() function sends the SITE command to the server.
The ftp_set_option() function sets various FTP runtime options.
ftp_rmdir() function deletes a directory.
The ftp_rename() function changes the file or directory name on the FTP server.
ftp_rawlist() function returns a detailed list of files in the specified directory.
The ftp_raw() function sends a raw command to the FTP server.
ftp_quit() function closes the FTP connection.
ftp_pwd() function returns the current directory name.
ftp_put() function uploads files to the server.
ftp_pasv() function sets passive mode on or off.
ftp_nlist() function returns the file list of the specified directory.
ftp_nb_put() function uploads files to the server (non-blocking).
The ftp_nb_get() function gets a file from the FTP server and writes it to a local file (non-blocking).
The ftp_nb_fput() function uploads an open file and saves it as a file on the FTP server (non-blocking).
The ftp_nb_fget() function downloads a file from the FTP server and saves it to a file that has been opened locally (non-blocking).
ftp_nb_continue() function continuously obtains/sends files.
The ftp_mkdir() function creates a new directory on the FTP server.
ftp_mdtm() function returns the last modification time of the specified file.
ftp_login() function logs in to the FTP server.
The ftp_get() function downloads a file from the FTP server.
The ftp_get_option() function returns various option settings for the current FTP connection.
ftp_fput() function uploads an open file to the FTP server.
The ftp_fget() function downloads a file from the FTP server and saves it to a local file that has been opened.
The ftp_exec() function requests the execution of a program or command on the FTP server. The ftp_delete() function deletes a file on the FTP server.
The ftp_connect() function establishes a new FTP connection.
ftp_close() function closes the FTP connection.
The ftp_chmod() function sets the permissions of the specified file on the FTP server.
ftp_chdir() function changes the current directory on the FTP server.
The ftp_cdup() function changes the current directory to the parent directory on the FTP server.
The ftp_alloc() function allocates space for files to be uploaded to the FTP server.
filter_var() function filters variables through the specified filter.
filter_var_array() function obtains multiple variables and filters them.
filter_list() function returns an array containing all supported filters.
filter_input_array() function obtains multiple inputs from outside the script and filters them.
filter_input() function gets input from outside the script and filters it.
filter_id() function returns the ID number of the specified filter.
filter_has_var() function checks whether a variable of the specified input type exists.
unlink() function deletes files.
umask() function changes the current umask.
touch() function sets the access and modification time of the specified file.
tmpfile() function creates a temporary file with a unique file name in read-write (w) mode.
The tempnam() function creates a temporary file with a unique file name.
The symlink() function creates a symbolic link.
The stat() function returns information about the file.
set_file_buffer() function sets the buffer size of the open file.
rmdir() function deletes empty directories.
rewind() function rewinds the position of the file pointer to the beginning of the file.
rename() function renames a file or directory.
realpath() function returns the absolute path.
readlink() function returns the target pointed to by the symbolic link.
readfile() function outputs a file.
popen() function opens the process file pointer.
The pclose() function closes the pipe opened by popen().
pathinfo() function returns file path information in the form of an array.
parse_ini_file() function parses a configuration file and returns the settings in an array.
move_uploaded_file() function moves the uploaded file to a new location.
mkdir() function creates a directory.
lstat() function returns information about a file or symbolic link.
linkinfo() function returns connection information.
link() function establishes a hard link.
is_writeable() function determines whether the specified file is writable.
is_writable() function determines whether the specified file is writable.
is_uploaded_file() function determines whether the specified file was uploaded via HTTP POST.
is_readable() function determines whether the specified file name is readable.
is_link() function determines whether the specified file name is a symbolic link.
is_file() function checks whether the specified file name is a normal file.
is_executable() function checks whether the specified file is executable.
is_dir() function checks whether the specified file is a directory.
glob() function returns the file name or directory matching the specified pattern.
fwrite() function writes to a file (safe for binary files).
ftruncate() function truncates the file to the specified length.
ftell() The current position of the function in the open file.
The fstat() function returns information about open files.
fseek() function locates in the open file.
The fscanf() function parses input from an open file according to a specified format.
fread() function reads files (safe for binary files).
fputs() function writes to a file (safe for use with binary files).
The fputcsv() function formats rows to CSV and writes them to an open file.
fpassthru() function outputs all remaining data at the file pointer.
fopen() function opens a file or URL.
fnmatch() function matches a file name or string based on a specified pattern.
flock() function locks or releases a file.
filetype() function returns the type of the specified file or directory.
filesize() function returns the size of the specified file.
The fileperms() function returns the permissions of the file or directory.
The fileowner() function returns the owner of the file.
The filemtime() function returns the last modification time of the file content.
The fileinode() function returns the inode number of the file.
The filegroup() function returns the group ID of the specified file.
The filectime() function returns the last inode modification time of the specified file.
fileatime() function returns the last access time of the specified file.
file_put_contents() function writes a string to a file.
The file_get_contents() function reads the entire file into a string.
file_exists() function checks whether a file or directory exists.
file() function reads the entire file into an array.
fgetss() function reads a line from an open file and filters out HTML and PHP tags.
fgets() function reads a line from the file pointer.
The fgetcsv() function reads in a line from the file pointer and parses the CSV fields.
fgetc() function reads a character from the file pointer.
fflush() function outputs the buffered content to a file.
The feof() function detects whether the end of file (eof) has been reached.
fclose() function closes an open file.
diskfreespace() function returns the free space in the directory. This function is an alias for the disk_free_space() function.
disk_total_space() function returns the total disk size of the specified directory.
disk_free_space() function returns the free space in the directory
dirname() function returns the directory part of the path.
clearstatcache() function copies files.
clearstatcache() function clears the file status cache.
chown() function changes the owner of the specified file.
chmod() function changes the file mode.
chgrp() function changes the group to which the file belongs.
The basename() function returns the file name part of the path.
set_exception_handler() handler() function

PHP Error and Logging function
set_exception_handler() function sets a user-defined exception handling function.
set_error_handler() function sets the user-defined error handling function. The
restore_exception_handler() function restores the previous exception handler, which was changed by the
set_exception_handler() function. The
restore_error_handler() function restores the previous error handler, which was changed by the
set_error_handler() function.
error_reporting() Sets PHP's error reporting level and returns the current level.
The error_log() function sends an error to the server error log, file, or remote target.
error_get_last() function gets the last error that occurred.
debug_print_backtrace() function outputs backtrace.
debug_backtrace() cktrace() function
PHP Error and Logging function
scandir() function returns an array containing files and directories in the specified path. The
rewinddir() function resets the directory handle opened by
opendir().
The readdir() function returns the entry in the directory handle opened by opendir().
The opendir() function opens a directory handle and can be used by closedir(), readdir() and rewinddir().
getcwd() function returns the current directory.
The closedir() function closes the directory handle opened by the opendir() function.
dir() function opens a directory handle and returns an object. This object contains three methods: read(), rewind() and close().
chroot() function changes the root directory of the current process to the specified directory.
chdir() function changes the current directory to the specified directory.
The time() function returns the Unix timestamp of the current time.
The strtotime() function parses any English text datetime description into a Unix timestamp.
The strptime() function parses the date/time generated by strftime().
strftime() function formats local time/date according to locale settings.
The mktime() function returns the Unix timestamp of a date.
The microtime() function returns the current Unix timestamp and microseconds.
localtime() function returns local time (an array).
idate() function formats local time/date into integers.
gmstrftime() function formats GMT/UTC time/date according to local locale settings.
gmmktime() function gets the UNIX timestamp of the GMT date.
gmdate() function formats GMT/UTC date/time.
The gettimeofday() function returns an array containing the current time information.
getdate() function obtains date/time information.
date() function formats a local time/date.
date_sunset() function returns the sunset time of the specified date and location.
date_sunrise() function returns the sunrise time of the specified date and location.
date_default_timezone_set() function sets the default time zone used for all date/time functions in scripts.
date_default_timezone_get() function returns the default time zone used by all date and time functions in the script.
checkdate() function verifies a Gregorian date.
The UnixToJD() function converts a Unix timestamp to a Julian day count.
JulianToJD() function converts the Julian calendar to Julian day counting.
JewishToJD() function converts the Jewish calendar to Julian day counting.
The JDToUnix() function converts a Julian day count to a Unix timestamp.
PHP Array Function
JDToGregorian() function converts the Julian day count to the Gregorian calendar.
The JDToFrench() function converts the Julian day count to the French Republic calendar.
JDMonthName() function returns the month string of the specified calendar.
JDDayOfWeek() function returns the day of the week the date is on.
GregorianToJD() function converts the Gregorian calendar to Julian day counting.
FrenchToJD() function converts the French Republican calendar to Julian day counting.
easter_days() function returns the number of days between Easter and March 21 in the specified year.
easter_date() function returns the Unix timestamp of Easter midnight in the specified year.
cal_to_jd() function converts the specified date to Julian day count.
cal_info() function returns an array containing information about the given calendar.
cal_from_jd() function converts the Julian day count to a date in the specified calendar.
cal_days_in_month() function returns the number of days in a month for the specified year and calendar. The usort() function sorts an array using a user-defined function.
The uksort() function uses a user-defined comparison function to sort the array by key name and maintain the index relationship.
uasort() function sorts an array using a user-defined comparison function and maintains index association (no new keys are assigned to elements).
sort() function sorts the values ​​of the given array in ascending order.
sizeof() function counts the number of cells in an array or the number of attributes in an object.
shuffle() function rearranges the elements in the array in random order.
rsort() function sorts the elements of the array in reverse order by key value. Basically the same function as arsort().
The reset() function points the internal pointer of the array to the first element and returns the value of this element.
range() function creates and returns an array containing elements in the specified range.
prev() HP prev() function
PHP Array function
pos() function is an alias of current() function. It returns the value of the current element in the array.
next() function moves the pointer pointing to the current element to the position of the next element and returns the value of the current element.
natsort() function sorts the elements in the given array using the natural order algorithm.
natcasesort() function sorts the elements in the given array using a case-insensitive natural order algorithm.
list() function assigns values ​​to a set of variables using elements in the array.
ksort() function sorts the array by key name, retaining the original keys for the array values.
krsort() function sorts the array in reverse order by key, retaining the original keys for the array values.
key() function returns the key name of the element currently pointed to by the internal pointer of the array.
in_array() function searches an array for a given value.
extract()
PHP Array function
end() function points the internal array pointer to the last element and returns the value of that element (if successful).
each() function generates an array consisting of the key name and key value of the element pointed to by the current internal pointer of the array, and moves the internal pointer forward.
current() function returns the current element (unit) in the array.
count() function counts the number of cells in an array or the number of attributes in an object.
compact() function creates an array consisting of the variables taken by the parameters. If there is an array in the parameter, the value of the variable in the array will also be obtained.
asort() function sorts the array and maintains the index relationship. Mainly used for sorting associative arrays where the order of cells is important.
arsort() function sorts the array in reverse order and maintains the index relationship. Mainly used for sorting associative arrays where the order of cells is important.
array_walk_recursive()
cursive() function
array_walk() function applies a callback function to each element in the array. Returns TRUE if successful, FALSE otherwise.
array_values() function returns an array containing all key values ​​in the given array, but does not retain the key names.
array_unshift() function inserts one or more elements at the beginning of the array.
array_unique() function removes duplicate values ​​from the array and returns the resulting array.
array_uintersect_assoc() function calculates the intersection of arrays with index checking, and uses a callback function to compare data.
array_uintersect() function calculates the intersection of arrays and uses callback functions to compare data.
array_udiff_uassoc() function returns the part that exists in the array1 array but does not exist in other arrays. The key names in the returned array remain unchanged.
array_udiff_assoc() function returns the part that exists in array1 but does not exist in other arrays.
array_udiff() function returns an array that includes all values ​​in the compared array but not in any other parameter array, and the key names remain unchanged.
array_sum() function returns the sum of all values ​​in the array.
The array_splice() function is similar to the array_slice() function, selecting a range of elements in an array, but instead of returning them, it deletes them and replaces them with other values.
array_slice() function removes a segment of value from the array based on conditions and returns it.
array_shift() function deletes the first element in the array and returns the value of the deleted element.
array_search() function is the same as in_array(), searching for a key value in the array. If the value is found, the key of the matching element is returned. If not found, returns false.
array_reverse() function reverses the order of elements in the original array, creates a new array and returns it. If the second parameter is specified as true, the element's key name remains unchanged, otherwise the key name is lost.
The array_reduce() function uses a callback function to iteratively reduce an array to a single value. If a third argument is specified, it will be treated as the first value in the array, or as the final return value if the array is empty.
array_rand() function randomly selects one or more elements from the array and returns it.
array_push() function adds one or more elements (push) to the end of the array of the first parameter, and then returns the length of the new array.
array_product() function calculates and returns the product of all values ​​in an array.
array_pop() function deletes the last element in the array.
array_pad() function inserts a specified number of elements with a specified value into an array.
array_multisort() function sorts multiple arrays or multidimensional arrays.
The array_merge_recursive() function, like the array_merge() function, merges the elements of one or more arrays, with the values ​​in one array appended to the previous array. and returns the resulting array.
array_merge() function merges two or more arrays into one array.
array_map() function returns the array after the user-defined function is applied. The number of arguments the callback function accepts should match the number of arrays passed to the array_map() function.
array_keys() function returns a new array containing all the key names in the array.
array_key_exists() function determines whether the specified key exists in an array. If the key exists, it returns true, otherwise it returns false.
array_intersect_ukey() function uses a callback function to compare key names to calculate the intersection of arrays.
array_intersect_uassoc() function uses a user-defined callback function to calculate the intersection of arrays and uses the callback function to compare the indexes.
array_intersect_key() function uses key name comparison to calculate the intersection of arrays.
array_intersect_assoc() function returns the intersection array of two or more arrays.
array_intersect() function returns the intersection array of two or more arrays.
array_flip() function returns a reversed array. If the same value appears multiple times, the last key name will be used as its value, and all other key names will be lost.
array_filter() function uses the callback function to filter the elements in the array. If the custom filter function returns true, the current value of the operated array will be included in the returned result array, and the result will be formed into a new array. If the original array is an associative array, the key names remain unchanged.
array_fill() function fills the array with the given value. The returned array has number elements and the value is value. The returned array is numerically indexed, starting at the start position and increasing. If number is 0 or less than 0, an error occurs.
array_diff_ukey() Returns an array containing the values ​​of all keys that appear in array1 but do not appear in any other parameter array. Note that the relationship remains unchanged. Unlike array_diff(), the comparison is based on keys rather than values.
The array_diff_uassoc() function uses a user-defined callback function (callback) to do index checking to calculate the difference between two or more arrays. Returns an array containing the values ​​in array1 but not in any of the other argument arrays.
array_diff_key() function returns an array containing all keys that are in the compared array but are not in any other parameter array.
array_diff_assoc() function returns the difference array of two arrays. This array contains all keys and values ​​that are in the array being compared, but are not in any of the other argument arrays.
array_diff() function returns the difference array of two arrays. This array contains all keys that are in the array being compared, but are not in any of the other parameter arrays.
array_count_values() function is used to count the number of occurrences of all values ​​in the array.
array_combine() function creates a new array by merging two arrays, one of which is the key name, and the value of the other array is the key value.
array_chunk() function splits an array into new array chunks.
array_change_key_case() function converts all KEYs in the array to uppercase or lowercase.
array() creates an array, with keys and values. If the key is omitted when specifying the array, an integer key is generated that starts at 0 and increments by 1.

[Recommended tutorial: PHP from beginner to proficient]

The above is the detailed content of [PHP Learning] A large collection of common PHP functions that are essential for beginners. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete