PHP provides a vast array of built-in functions that cover a wide range of tasks, from string manipulation to file handling, database interactions, and more. Each function serves a specific purpose, making it easier to handle various tasks within your PHP applications without needing to reinvent the wheel. Here’s a categorized list with brief explanations of some commonly used built-in PHP functions:
String Functions
strlen($string): Returns the length of a string.substr($string, $start, $length): Returns part of a string.str_replace($search, $replace, $subject): Replaces all occurrences of search string with the replacement string in the subject string.strtolower($string),strtoupper($string): Converts a string to lowercase or uppercase.trim($string),ltrim($string),rtrim($string): Remove whitespace or other specified characters from the beginning, end, or both sides of a string.
Array Functions
count($array): Returns the number of elements in an array.
$numbers = array(1, 2, 3, 4, 5);
$count = count($numbers);
// $count is 5
array_push($array, $value), array_pop($array): Add elements to the end of an array, or remove the last element.
Examples of array_push()
Adds one or more elements to the end of an array.
$fruits = array("apple", "banana");
array_push($fruits, "orange", "pear");
// $fruits is now array("apple", "banana", "orange", "pear")
array_merge($array1, $array2): Merge one or more arrays into one array.array_keys($array),array_values($array): Return all the keys or values of an array.sort($array),rsort($array): Sort an array in ascending or descending order.
File System Functions
file_get_contents($filename): Reads a file into a string.file_put_contents($filename, $data): Write a string to a file.fopen($filename, $mode),fclose($handle): Open and close files.filesize($filename): Returns the file size in bytes.
Math Functions
abs($number): Returns the absolute (positive) value of a number.round($number, $precision): Rounds a floating-point number to a specified precision.min($number1, $number2, ...),max($number1, $number2, ...): Returns the minimum or maximum value from a list of arguments.
Date and Time Functions
date($format): Formats a timestamp into a human-readable date.time(): Returns the current Unix timestamp.strtotime($time): Parses an English textual datetime into a Unix timestamp.
Database Functions
mysqli_connect(),mysqli_query(),mysqli_fetch_assoc(): Functions for interacting with MySQL databases using the mysqli extension.PDO::__construct(),PDO::query(),PDOStatement::fetch(): Functions for interacting with databases using PDO (PHP Data Objects).
Miscellaneous Functions
header($header): Send a raw HTTP header.mail($to, $subject, $message): Send an email.json_encode($value),json_decode($jsonString): Encode and decode JSON data.
.
