Top 80 Essential PHP functions asked in any Interview

This post contains the list of PHP functions that are frequently asked in various interview from fresher’s as well as experienced candidates. These are the parts of basic and core PHP. One must be familiar with these functions, I have just mentioned the definition in one line for each functions. They are frequently used in our application. Hope you will find this helpful.

PHP functions are similar to other programming languages. A PHP function is a piece of code which takes one more input in the form of parameter and does some processing and returns a value.

You already have seen many PHP functions like fopen() and fread() etc. They are built-in functions but PHP gives you option to create your own functions as well.

There are two parts which should be clear to you −

  • Creating a PHP Function
  • Calling a PHP Function

In fact you hardly need to create your own PHP function because there are already more than 1000 of built-in library functions created for different area and you just need to call them according to your requirement.

Please refer to PHP Function Reference for a complete set of useful functions.

PHP functions

String PHP Functions

Top 80 Essential PHP functions
  1. strlen() : returns the length of string passed.
  2. stristr() : returns rest of the string after the first occurence of a string in another string.
  3. stripos() : find the position of the first occurence of the string in another string.
  4. strip_tags() : returns string from html tags.
  5. strchr() : find first occurence of a string in another string and returns rest of the string.
  6. str_word_count() : returnd number of words in a string.
  7. str_split() : returns an array of charecters that string contains, when passed to it.
  8. str_replace() : search and replace a substring in a string by another substring.
  9. str_pad() : provide a virtual length to a string. It adds desired charecter to a string to make it up to required length.
  10. str_repeat() : Return a repeated string by a number of times.
  11. str_getcsv() : Parse a string to get the fields for CSV.
  12. rtrim() : remove white spaces from a string from right side.
  13. ord() : When we need to find ASCII value of the first charecter of the string we use ord().
  14. nl2br() : Conver all the new line charecters to BR tag of HTML.
  15. strstr() : returns rest of the string after the first occurence of a string in another string, find only case sensitive string.
  16. strtok() : breaks a strings into substrings
  17. strtoupper() : convert the case of string into uppercase.
  18. strtolower() : convert the case of string into lowercase.
  19. substr() : return a substring from a string of a length and from starting position.

String Operations PHP Functions

  1. trim() : removes the white spaces from a string from left and right.
  2. ucfirst() : convert the case of first letters of all words in a string to uppercase.
  3. wordwrap() : break lines after a length.
  4. print() : output the result string when passed to it.
  5. print_r() : prints a resources ,object or an array along with the indexes.
  6. unlink() : delete a file from its location.
  7. unset() : set the value of a variable undefined.
  8. isset() : check whether the variable is defined or not.
  9. empty() : check whether an array is empty.

    Array PHP Functions
  10. array_chunk() : breaks an array into chunks of small arrays.
  11. array_combine() : combine two arrays of equal size where one is used for keys and another one is used for values.
  12. array_count_values() : count and returns the number of values of an array
  13. array_diff() : returns an array having difference between two arrays.
  14. array_flip() : flip key and value simultaneously.
  15. array_filter() : filter the values of an array based on a callback function.
  16. array_key_exists() : returns true if a key exists in an array.
  17. array_keys() : returns the array of keys from an array.
  18. array_map() : apply some operation on each value of an array and return a new array with modified values.
  19. array_merge() : merge the values of two array while retaining their keys.
  20. array_merge_recursive() : merge multidimensional arrays.
  21. array_push() : add a new value in an array at the end.
  22. array_rand() : select some random keys from an array.
  23. array_replace() : replace values in an array from the values in another array.
  24. array_reverse() : reverse the order of array and return new array.
  25. array_search() : search a value in an array and return the key of the value.
  26. array_shift() : remove the first element in an array.
  27. array_sum() : sum up all the values in an array.
  28. array_unique() : remove all the replicated values in an array.
  29. array_values() : returns an array of values with numeric index.
  30. array_walk() : Go to each value and run over an user defined function.
  31. array_walk_recursive() : Does the same recursively for an array.
  32. compact() : The compact() function creates an array from variables and their values.
  33. asort() : Sort an array values in ascending order.
  34. arsort() : Sort an array values in descending order.
  35. in_array() : returns true if a value find in an array.
  36. key() : return the key from the current pointer position.
  37. krsort() : sort and array based on keys and in descending order.
  38. ksort() : sort and array based on keys and in ascending order.
  39. range() : create an array from the range passed to it.
  40. date_create() : create a new dateTime object.
  41. date_create_from_format() : Create a user defined date from given format.
  42. date_diff() : returns difference between two dates.
  43. date_sub() : suntracts some period of time from a given date.
  44. date() : output the current date and time based on parameters given to it.
  45. gettimeofday() : output current time.
  46. gmmktime() : output UNIX time for GMT.
  47. localtime() : returns local time as UNIX timestamp.
  48. strtotime() : convert a string having datetime information into UNIX date.
  49. time() : eturn the current time.
  50. ceil() : returns the next interger value of the floating number passed to it.
  51. floor(): returns the next lowest integer value
  52. abs() : returns the absolute value passed to it.
  53. base_convert() : convert the base of number system.
  54. is_nan() : check whether a value is Not a Number.
  55. is_infinite() : check wherther a value is Infine.
  56. max() : find the max value from an array.
  57. min() : find minimum value from an array.
  58. mt_rand() : based on Mersenne Twister algorithm creates a random number.
  59. rand() : generate a random number
  60. round() : returns a floating point number up to a particular place of decimal point.
  61. sqrt() : returns the square root of the value passed to it.

About Author

After years of Technical Work, I feel like an expert when it comes to Develop wordpress website. Check out How to Create a Wordpress Website in 5 Mins, and Earn Money Online Follow me on Facebook for all the latest updates.

Leave a Comment