Compilation of commonly used PHP functions

jacklove
Release: 2023-03-27 13:08:02
Original
2544 people have browsed it

This article organizes the php functions.

array()

array(value1,value2…..) Create an array

array_chunk(array,size,preserve_keys) Split a number into new array chunks[ tk]

array_combine(keys,values) forms a new array by merging two arrays (key name array, key value array)

array_count_values(array) is used to count all values in the array Number of occurrences

array_diff(array1,array2,...) Compare arrays and return the difference set of two arrays (only compare key values)

array_diff_assoc(array1,array2,..) Compare Array returns the difference between two arrays (compares key names and key values)

array_diff_key(array1,array2,...) Compares arrays and returns the difference between two arrays (compares only key names)

array_fill(index,number,value) Fills the array with the given key value

array_filter(array, the callback function to be used) Use the callback function to filter the elements in the array

array_flip( array) Reverse/exchange the key names in the array and the corresponding associated key values [flp]

array_keys(array) Return all key names in the array

array_merge(array1,array2,.. ) Merge one or more arrays into an array [m:rd]

array_pad(array,size,value) Insert the specified number of elements with the specified value into the array

array_pop (array) Delete the last element

array_push(array) Add the array at the end

array_shift(array()) Delete the number and return the deleted element value

array_unshift(array )) The first element in the group adds one or more elements

array_rand(array,number) Randomly selects one or more arrays from the array

array_replace(array1,array2. ..) Replace the value of the first array with the value of the following array

array_reverse(array) The array is reversed and returns a new array

array_search(value,array, strict(optional true ,flase)) The search value returns the key name. True searches for elements with the same key name and value

array_slice(array,start,length,preserve) Returns the selected part of the array

array_splice(array,start,length,array) Returns the specified Remove the elements and replace them with others

array_unique(array) Delete duplicate values in the array [junik]

array_values(array) Return all values in the array

array_key_exists (key,array) Find whether the array key exists

count(array) Return the number of elements in the array. [kant]

in_array('value',$array,bool) Check the array If the specified value exists in is set to TRUE, the in_array

function checks whether the type of the searched data is the same as the value of the array.

key(array) Get the key name from the associative array

list(array1, array2...) Assign the values in the array to some array variables

krsort(array) Sort the associative array in descending order by key name

ksort(array) Sort the associative array in ascending order by key name

arsort(array) Sort the associative array in descending order by key value

asort(array ) Sort the associative array in ascending order by key value

String

strtolower(string) Convert the string to lowercase letters

strtoupper(string) Convert the string to uppercase letters

strtr(“string”,”from”,””to”) Convert the undetermined characters in the string

substr(string,start, length) Return a part of the string

substr_count(string,substring,start,length) Counts the number of times a substring appears in a string

substr_replace(string,inserted character,start,length) Replaces part of the string with another character

trim(string, which characters (optional)) removes whitespace characters and other characters on both sides of the string trim

ucfirst(string) converts the first character of the string to uppercase

ucwords(string) Convert each first character of the string to uppercase

sha1(string, optional character) Calculate the SHA-1 hash of the string

sha1_file (file) Calculate the SHA hash of the file

sprintf (how to format the variables) Write the formatted string into a variable

str_getcsv(string, delimiter, wraparound character , escape character) Parse the CSV string into an array

str_ireplace(find value, replace value) Replace some characters in the string (case insensitive)

str_pad(string, length) Fill the string to the new length

str_repeat(string, times) Repeat the string the specified number of times

str_replace(search value, replace value) Replace some parts of the string Characters (case sensitive)

str_shuffle(string) Randomly shuffle all the characters in the string [fl] Shuffle/Chaos

str_split(string.length) Split the string into In the array

str_word_count(string) Calculate the length of words in the string

strchr(string,search,before_search) Find the first occurrence of a string in another string strstr()

implode(content,array) Returns a string consisting of array elements.[mplode]

lcfirst(string) The first character of the string is converted to lowercase

ltrim( string, defined characters) Remove blank characters or other characters on the left side of the string

md5(string) Calculate the MD5 hash

md5_file(file) Calculate the MD5 hash of the file

ord(string) Returns the ASCII code value of the first character in the string

parse_str(string,array(optional) Parses the query string into a variable

printf (format value) Output formatted string

print(strings) Output one or more strings

strip_tags(string) Strip the HTML and PHP tags of the string

stripcslashes(string) Removes the backslash lashes added by the addcslashes() function [l]

stripslashaes string () Removes the backslash added by the addslashees() function

stripos(string,find,start) Returns the position of the first occurrence of the string in another string (case insensitive )

stristr(search, searched string) Finds the first occurrence of a string in another string (case insensitive)

strlen(string) Returns a string The length of

strpos(string, the character to be searched for) returns the position of the first occurrence of a string in another string (case insensitive)

strrchr(string, the character to be searched for characters) Find the last occurrence of a string in another string

strrev(string) Reverse a string.

strripos(string, the character to be searched for) Find the last occurrence of a string in another string (case insensitive)

strrpos(string, the character to be searched for) Find the character The position of the last occurrence of a string in another string (case insensitive)

addcslashes(string, range) Returns a string with a backslash added before the specified character

addslashes (string) Returns a string with a backslash added before the predefined character

chr(ASCII value.) Returns the character from the specified ASCII code value

chunk_split(string,length,end) Split the string into a series of smaller parts

count_chars() Return the character information used in the string

echo(strings) Output one or more strings

explode () Spread characters into an array

Date

date_default_timezone_get() Returns the default time zone used by all Date/Time functions

date_default_timezone_set() Sets the default time zone used by all The Date/Time function uses

date() to format local date and time

time() to return the Unix timestamp of the current time

Math

pi () Returns the value of PI

pow(x,y) Returns x raised to the yth power

rand() Returns a random integer (0-1)

round( ) Round floating point integers

abs() Take the absolute value

ceil() Round up

floor() Round down

max() Get the direct value in the array

min() Get the minimum value in the array

mt_rand() Use the Mersenne Twister algorithm to generate a random integer

is_nan() Judgment Whether it is a non-numeric value

File

fwrite(file,string,length) writes the open file

is_dir(file) determines whether the file is in the same directory

is_file(file) Determine whether the file is a regular file

mkdir(directory name) Create a directory

move_uploaded_fild(file,newloc) Move the uploaded file to a new location

parse_ini_file(file) Parse a configuration file

rename(file) Remove an empty directory from a named file or directory

rmdir(directory)

unlink(filename) Delete the file

filesize(filename) Return the file size

fopen(filename, type) Open a file or URL

fputs(file,string,length) Write the content into a Alias for fwrite() in an open file

fread(file,length) Read an open file

fseek(file,new position) Position in an open file

copy(file,to_file) Copy the file to the destination

dirname(path path) Return the directory name part of the path

fclose(file) Close the open file

fgetc(file) Returns characters from an open file

fgetcsv(file) Parses a line from an open file, validating CSV fields

fgets(file) Returns a line from an open file

fgetss(file) Returns a line from an open file and filters out HTML and PHP

file(path) Reads a file into an array

file_exists(file) Checks a file Or whether the directory exists

file_get_contents(file) Read the file into a string

file_put_contents(file,data) Write the string into the file

Directory

chdir(directory) Change the current directory

closedir(dir_handle optional) close the record handle

dir() Return an instance of the directory class

getcwd(directory) Return the current Working directory

opendir(path) Open the directory handle

readdir(dir_handle optional) Return the conditions of the directory handle

scandir(directory) Return the files and directories in the specified directory The array

This article organizes the php functions. For more related content, please pay attention to the php Chinese website.

Related recommendations:

PHP implements WeChat refund application process example code

In PHP, %s and % What do d mean?

think php5 multi-table query paging code method to get the total number

The above is the detailed content of Compilation of commonly used PHP functions. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!