search
HomeBackend DevelopmentPHP TutorialCompilation of commonly used PHP functions

Compilation of commonly used PHP functions

May 22, 2018 pm 03:07 PM
phpfunctiontidy

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!

Statement
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
PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Choosing Between PHP and Python: A GuideChoosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Frameworks: Modernizing the LanguagePHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AM

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHP's Impact: Web Development and BeyondPHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

How does PHP handle object cloning (clone keyword) and the __clone magic method?How does PHP handle object cloning (clone keyword) and the __clone magic method?Apr 17, 2025 am 12:24 AM

In PHP, use the clone keyword to create a copy of the object and customize the cloning behavior through the \_\_clone magic method. 1. Use the clone keyword to make a shallow copy, cloning the object's properties but not the object's properties. 2. The \_\_clone method can deeply copy nested objects to avoid shallow copying problems. 3. Pay attention to avoid circular references and performance problems in cloning, and optimize cloning operations to improve efficiency.

PHP vs. Python: Use Cases and ApplicationsPHP vs. Python: Use Cases and ApplicationsApr 17, 2025 am 12:23 AM

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool