Loading...
Loading...

PHP Functions Overview

In PHP, functions are blocks of reusable code that perform specific tasks. Below is a comprehensive list of built-in PHP functions categorized by their general purpose:

1. String Functions

  • strlen(): Get the length of a string.
  • strpos(): Find the position of the first occurrence of a substring in a string.
  • str_replace(): Replace all occurrences of a search string with a replacement string.
  • strtoupper(): Convert a string to uppercase.
  • strtolower(): Convert a string to lowercase.
  • ucfirst(): Capitalize the first character of a string.
  • trim(): Strip whitespace (or other characters) from the beginning and end of a string.
  • substr(): Return part of a string.
  • explode(): Split a string by a string delimiter.
  • implode(): Join array elements into a string.

2. Array Functions

  • count(): Count the elements in an array.
  • array_merge(): Merge one or more arrays.
  • array_diff(): Compute the difference of arrays.
  • array_slice(): Extract a slice of an array.
  • in_array(): Check if a value exists in an array.
  • array_keys(): Return all the keys of an array.
  • array_values(): Return all the values of an array.
  • array_map(): Apply a callback to the elements of an array.
  • array_filter(): Filter elements of an array using a callback function.

3. Mathematical Functions

  • abs(): Get the absolute value.
  • round(): Round a floating-point number.
  • floor(): Rounds down to the nearest integer.
  • ceil(): Rounds up to the nearest integer.
  • rand(): Generate a random integer.
  • max(): Find the highest value in an array or list of values.
  • min(): Find the lowest value in an array or list of values.

4. Date and Time Functions

  • date(): Format a local date and time.
  • strtotime(): Parse an English textual datetime description into a Unix timestamp.
  • time(): Return the current Unix timestamp.
  • mktime(): Get the Unix timestamp for a date.
  • date_diff(): Calculate the difference between two DateTime objects.

5. File Handling Functions

  • fopen(): Open a file or URL.
  • fclose(): Close an open file pointer.
  • fread(): Read from a file.
  • fwrite(): Write data to a file.
  • file_get_contents(): Get the contents of a file into a string.
  • file_exists(): Check whether a file or directory exists.
  • unlink(): Delete a file.

6. Error Handling Functions

  • error_reporting(): Set the level of error reporting.
  • set_error_handler(): Sets a user-defined error handler function.
  • trigger_error(): Generates a user-level error/warning/notice.

7. Variable Handling Functions

  • isset(): Determine if a variable is set and is not NULL.
  • empty(): Determine whether a variable is empty.
  • unset(): Unset a variable.

8. Type Casting and Conversion Functions

  • (int): Cast a variable to an integer.
  • (float): Cast a variable to a float.
  • (string): Cast a variable to a string.
  • (array): Cast a variable to an array.
  • (object): Cast a variable to an object.

9. Session Functions

  • session_start(): Start a new session or resume an existing session.
  • session_destroy(): Destroy all data registered to a session.
  • $_SESSION: Superglobal array to store session variables.

10. JSON Functions

  • json_encode(): Returns a JSON representation of a value.
  • json_decode(): Decodes a JSON string.

11. Miscellaneous Functions

  • gettype(): Returns the type of a variable.
  • var_dump(): Dumps information about a variable.
  • die(): Output a message and terminate the current script.
  • exit(): Output a message and terminate the current script.

12. Network Functions

  • curl_init(): Initialize a cURL session.
  • curl_setopt(): Set an option for a cURL transfer.
  • curl_exec(): Execute a cURL session.
  • curl_close(): Close a cURL session.
0 Interaction
1.7K Views
Views
11 Likes
×
×
🍪 CookieConsent@Ptutorials:~

Welcome to Ptutorials

Note: We aim to make learning easier by sharing top-quality tutorials.

We kindly ask that you refrain from posting interactions unrelated to web development, such as political, sports, or other non-web-related content. Please be respectful and interact with other members in a friendly manner. By participating in discussions and providing valuable answers, you can earn points and level up your profile.

$ Allow cookies on this site ? (y/n)

top-home