ADVERTISEMENT
ADVERTISEMENT

What are Built-in functions in PHP?

Built-in functions in PHP are pre-defined functions provided by the language to perform common tasks efficiently. They simplify operations like string handling, array manipulation, date processing, and mathematical calculations. These functions save time by eliminating the need to write code from scratch for routine tasks. You can use them directly by calling their names with the required parameters.

Commonly Used Built-in Functions in PHP

Function Description Example Usage Output
strlen() Returns the length of a string. strlen("Hello") 5
strtolower() Converts a string to lowercase. strtolower("HELLO") hello
strtoupper() Converts a string to uppercase. strtoupper("hello") HELLO
substr() Returns part of a string. substr("Hello", 1, 3) ell
strpos() Finds the position of the first occurrence of a substring. strpos("Hello", "e") 1
array_sum() Calculates the sum of array elements. array_sum([1,2,3]) 6
count() Counts elements in an array or object. count([10, 20, 30]) 3
in_array() Checks if a value exists in an array. in_array(2, [1,2,3]) true
array_merge() Merges two or more arrays. array_merge([1],[2]) [1,2]
explode() Splits a string into an array. explode(",", "a,b,c") ["a","b","c"]
implode() Joins array elements into a string. implode("-", ["a","b","c"]) a-b-c
date() Returns the current date/time. date("Y-m-d") 2025-02-23 (example)
time() Returns the current Unix timestamp. time() Unix timestamp
isset() Checks if a variable is set and not null. isset($var) true or false
empty() Checks if a variable is empty. empty("") true
round() Rounds a number to the nearest integer. round(4.7) 5
rand() Generates a random integer. rand(1, 10) Random number (1–10)
max() Finds the highest value in an array. max([1,2,3]) 3
min() Finds the lowest value in an array. min([1,2,3]) 1
abs() Returns the absolute value of a number. abs(-5) 5

ADVERTISEMENT

ADVERTISEMENT