Functions are blocks of codes that perform specific task in php. It makes the codes reusable and shorthand. it can be categorized into two groups.
Predefined functions are the inbuilt functions of php. These functions can be subdivided into multiple categories as stated below.
string functions
numeric functions
date and time functions
array functions
directory functions
strtolower(); -> converts all characters of the string to lower case
strtoupper(); -> converts all characters of the string to upper case
ucfirst(); -> converts first letter to upper case
ucwords(); -> converts first letter of each word to upper case
strlen(); -> counts number of characters in a string and returns integer value
trim(); -> trims unnecessary spaces
ltrim(); -> trims unnecessary spaces from left
rtrim(); -> trims unnecessary spaces from right
sprintf("%s,%s,%s",$a,$b,$c); -> placeholder to keep the value
str_word_count() -> count the number of words
$count = str_word_count($x,1) -> returns array
strstr(); echo strstr($str,U,true);
stristr(); case insensitive strstr
str_replace() -> search and replace characters from the string
str_repeat() -> repeats the string
substr(int,int) -> prints a string from defined initial character number to defined last number
strpos() -> finds position of the string
abs() -> returns positive value of a number
sqrt() -> returns square root of a number
round() -> rounds a floating number
floor() -> rounds a number down to a nearest integer
ceil() -> rounds a number up to a nearest integer
rand() -> generates a random integer
mt_rand() -> generates random number between defined inital and end number
pow() -> returns x raised to the power of y
pi() -> returns the value of pi
min() -> returns the lowest value from an array
max() -> returns the highest value from an array
fmod() -> returns the remainder from x/y {%}
bindec() -> converts a binary number to a decimal number
decbin() -> converts a decimal number to a binary number
deg2rad() -> converts a degree value to a radian value
rad2deg() -> converts a radian value to a degree value
array() -> creates an array
sizeof() -> counts the number of values in an array
sort() -> sorts an indexed array in ascending order
in_array() -> checks if a specified value is in array
list() -> keep array values in variable
compact() -> keeps variable values in associative array
arsort() -> sorts an associative array in descending order according to the value
array_unique() -> removes duplicate values from an array
explode() -> converts string to array
implode() -> converts array to string
extract() -> converts array to variable
array_sum() -> returns the sum of values in an array
array_shift() -> removes the first element of an array and returns the first value from the array
array_pop() -> deletes the last element from an array
array_merge() -> merges multiple arrays
array_search() -> searches for a defined value in an array and returns the key for that value
array_reverse() -> returns an array in reverse order
array_keys() -> returns all the keys from an array
getcwd() -> get current working directory
mkdir() -> make directory
rmdir() -> remove directory
dirname() -> directory name
__DIR__ -> directory name
__FILE__ -> filename along with directory
__LINE__ -> line number
file_exists() -> checks if file exists and returns boolean value
unlink() -> remove file
is_file() -> boolean
is_dir() -> boolean
scan_dir() -> returns array of files present in the directory
file_size() -> returns file size in bytes
filectime() -> file created time (timestamps)
pathinfo() -> returns array / string based on arguments
copy() -> copy file
Leave a comment