100 PHP Functions You Should Know – Part 18 min read

In this tutorial we will discover the list of the 100 most used native functions in PHP.

1. count

Returns the number of elements in an array.


2. is_array

Is used to determine whether a variable is an array or not.



3. substr

Returns part of a string.



4. in_array

Finds a specific value in an array.



5. explode

Divide a string into an array.



6. implode

Returns a string from the elements of an array.


7. str_replace

Divide a string into an array.


8. strlen

Returns the length of a string.



9. array_merge

Merges one or more tables into a single table.



10. strpos

Finds the position of the first occurrence of one string within another string.



11. preg_match

Finds the pattern in a string, returning true if the pattern exists, otherwise false.


12. sprintf

Creates a formatted string from one or more arguments.



13. trim

Removes spaces and other predefined characters from both sides of a string.



14. strtolower

Converts a string to lowercase.



15. file_exists

Checks whether a file or directory exists or not.


16. is_string

Is used to determine whether a variable is a string or not.



17. preg_replace

To perform a pattern match on a string, then replace the match with specific text. This example removes spaces in $str.



18. file_get_contents

Read a file in a character string.


19. array_key_exists

Checks an array for a specified key and returns true if the key exists and false if the key does not exist.



20. array_keys

Returns an array containing the keys.



21. dirname

Returns the name of the directory for a given path.


22. function_exists

Check if a function exists or not in the PHP script.



23. array_map

Sends each value of an array to a user-defined function and returns an array with the new values, provided by the user-defined function.



24. get_class

This function retrieves the class name of the given object.


25. class_exists

This function checks if the given class has been defined.


26. is_object

Is used to determine whether a variable is an object or not.


27. time

Function returns the current time as seconds.


28. json_encode

Function that converts PHP objects to JSON.


29. date

This function allows you to format a date.


30. is_null

Function is used to test whether a variable is NULL or not.

31. is_numeric

Is used to check whether a variable is numeric or not.



32. array_shift

Removes the first element from an array and returns the value of the deleted element.


33. defined

Checks if a constant exists.


34. is_dir

Checks whether the specified file is a directory.


35. json_decode

Decode a JSON string


36. header

Sends a raw HTTP header to a client.


37. strtoupper

Converts a string to uppercase.


38. array_values

Returns an array containing all the values ​​of an array.


39. md5

Calculates the MD5 hash of a string.


40. method_exists

It checks if the “write” method exists in the object supplied as the “$book” parameter.


41. file_put_contents

Write the string of characters “Welcom to Code4Exampe! “In the file” file.txt.


42. rtrim

Removes spaces or other predefined characters to the right of a string.


43. array_pop

Remove the last element from an array.


44. unlink

Delete a file.


45. basename

Returns the file name from a path.


46. realpath

Returns the absolute path.


47. call_user_func

Is used to call a callback function given in the first parameter and passes the remaining parameters as arguments. It is used to call user-defined functions.


48. call_user_func_array

Calls a callback function and passes the parameters to it. The parameters are encapsulated in an array and then assigned one by one to the callback function parameter list. You call the callback function by the fully qualified name assigned to it in the first parameter. If the callback function returns a value, that value is returned by call_user_func_array.


49. fopen

Open a file or URL.


50. microtime

Returns the current Unix timestamp in microseconds.



The 100 PHP Functions You Should Know – Part 2



1 Comment

Leave a Comment