There are hundreds of functions in PHP, but most of them are rarely or never used. In the following you will find the most important PHP functions. For a complete list of features, see the PHP.net Function Guide .

array functions

  • array_key_exists($key, $array)  – Check if a key exists in an array.
  • arsort($array)  – Sort an array in reverse order and get the index association.
  • asort($array)  – Sorts an array and gets the index association.
  • count($array)  – Counts all elements of an array or something in an object.
  • explode($divisor, $string)  – Splits the $ string in all parts of the divider and returns the individual parts as an array.
  • implode($divisor, $array) – Connects all elements of the array and returns a string. $ Divisor was inserted between the elements.
  • in_array($search, $array)  – Checks if a value exists in an array.
  • krsort($array)  – Sort an array by keys in reverse order.
  • ksort($array)  – Sort an array by keys.
  • natcasesort($array)  – Sorts an array in “natural order”, case insensitive is ignored.
  • natsort($array)  – Sorts an array in “natural order”.
  • print_r($array)  – Returns the contents of an array, including its keys.
  • rsort($array)  – Sorts an array in reverse order.
  • shuffle($array)  – Mix the elements of an array.
  • sort($array)  – Sorts an array.

More information about arrays can be found in our article Arrays .

file Operations

  • copy($ source, $ target)  – Copies the file $ source to the new destination $ target.
  • file_exists($filename)  – Returns true if the file exists.
  • file_get_contents($filename)  – Reads the entire file and returns the content as a string.
  • file_put_contents ($filename, $content)  – Overwrites the file with new content.
  • file ($filename) – Read line by line a file. Each line is returned as an element of an array.
  • filesize($filename)  – Returns the size of a file in bytes.
  • is_dir($path)  – Returns true if the path is a directory.
  • is_file($path)  – Returns true if the path is a file.
  • is_readable($file)  – Returns true if the file can be read.
  • is_writable($file)  – Returns true if the file can be written to.
  • mkdir($newdirectory)  – Creates a new directory.
  • move_uploaded_file($source, $target)  – Moves a uploaded file.
  • rmdir($directory path)  – Deletes a directory.
  • unlink($file path)  – Deletes a file.

More information on file functions can be found in our articles Reading Files and Writing Files.

Date / Time functions

  • date($format, $timestamp)  – Formats the timestamp according to the format.
  • microtime()  – Returns the current Unix timestamp / timestamp with microseconds.
  • mktime($hour, $minute, second, $month, $day, $year)  – Returns the Unix timestamp / timestamp for a date.
  • strtotime($string)  – Converts any date specified in English text form to a UNIX timestamp.
  • time() – Returns the current Unix timestamp / timestamp (the seconds since 1970).

PHP Mathematical functions

  • abs($number)  – absolute value of the number.
  • ceil($number)  – Round up.
  • floor($number)  – rounding off.
  • max($number1, $number2, …) – maximum value of the numbers. Works on arrays using max ($array).
  • min($number1, $number2, …) – Minimum value of the numbers. Works on for arrays using min ($array).
  • rand($min, $max)  – Generates a random number between $ min and $ max.
  • round($number, $pay_off)  – Rounds a floating-point value.
  • sqrt($number)  – Calculates the square root.

MySQL functions

  •     $pdo = new PDO (‘mysql: host = localhost; dbname = databasename’, ‘username’, ‘password’); – Creates a new database connection using PDO.
  •     $pdo->query($sql) – Sends an SQL query to the database.
  •     $statement = $pdo->prepare($sql) – Generates a prepared statement .
  •     $statement->execute($parameter) – Executes a prepared statement .
  •     $statement->fetch() – iterates over the result of the prepared statement .
  •     $statement->rowCount() – Returns the number of rows of the result.
  •     $statement->errorInfo() – Returns the error information for an SQL error.

Detailed information about MySQL and PDO can be found in our MySQL tutorial.

string functions

  • addslashes($string)  – Precedates single and double quotes with a backslash.
  • explode ($divisor, $string)  – Splits the $string in all parts of the divider and returns the individual parts as an array.
  • htmlentities($string)  – Converts special characters to the corresponding HTML characters.
  • htmlspecialchars($string)  – Converts special characters to the corresponding HTML characters.
  • implode($divisor, $array) – Connects all elements of the array and returns a string. $ Divisor was inserted between the elements.
  • md5($string)  – Returns the md5 hash.
  • nl2br($string)  – Converts line breaks to HTML line breaks (<br>).
  • sha1($string)  – Returns the sha1 hash.
  • preg_match($pattern, $text) – Search for a regular expression in a text.
  • preg_replace($ pattern, $ replace, $ text) – Replaces occurrences of a  regular expression in a text.
  • str_ireplace($ search, replace $, $ text) – Replaces in $ text all occurrences of $ search by replacing $. Uppercase and lowercase letters are ignored.
  • str_replace($search, $replace, $text) – Replaces in $ text all occurrences of $ search by replacing $. Uppercase and lowercase letters are considered.
  • stripos($text, $search) – Finds the first occurrence of a substring in a string and returns its position. Uppercase and lowercase letters are ignored.
  • strlen($string)  – Returns the length of the string.
  • strpos($text, $search)  – Finds the first occurrence of a substring in a string and returns its position.
  • strtolower($string)  – Converts all letters to lowercase.
  • trim($string)  – Removes whitespaces (spaces, line breaks, tabs, etc.) at the beginning and end of the string.

Other functions

  • include($file path) – Bind a file.
  • include_once($filepath) – Bind a file at most once.
  • mail ($recipient, $subject, $text, $sender)  – Sends an e-mail.
  • require($file path) – Bind a file.
  • require_once($filepath) – Bind a file at most once.
  • session_destroy() – Deletes the session of the user.
  • session_start() – Starts or continues a session.
  • var_dump($variable)  – Returns the contents of a variable including type information.

How useful was this post?

Click on a star to rate it!

Average rating / 5. Vote count:

As you found this post useful...

Follow us on social media!

We are sorry that this post was not useful for you!

Let us improve this post!