When it comes to fundamental of a language, there are many pre-defined functions and one should know about them. These are also known as library functions and are very useful when you are coding for something.
PHP provides a lot of such functions and they are very helpful and useful . Here we listed some popular functions and their one line explanations. When you are going for an interview this should be in mind that along with logical and coding questions Interviewer can also ask about these functions. for example – “What is strlen() function in PHP?”
This post contains the list of PHP functions that are frequently asked in various interview from freshers 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.
- strlen() : returns the length of string passed.
- stristr() : returns rest of the string after the first occurrence of a string in another string.
- stripos() : find the position of the first occurrence of the string in another string.
- strip_tags() : returns string from html tags.
- strchr() : find first occurrence of a string in another string and returns rest of the string.
- str_word_count() : returns number of words in a string.
- str_split() : returns an array of characters that string contains, when passed to it.
- str_replace() : search and replace a sub string in a string by another sub string.
- str_pad() : provide a virtual length to a string. It adds desired character to a string to make it up to required length.
- str_repeat() : Return a repeated string by a number of times.
- str_getcsv() : Parse a string to get the fields for CSV.
- rtrim() : remove white spaces from a string from right side.
- ord() : When we need to find ASCII value of the first character of the string we use ord().
- nl2br() : Convert all the new line characters to BR tag of HTML.
- strstr() : returns rest of the string after the first occurrence of a string in another string, find only case sensitive string.
- strtok() : breaks a strings into sub strings
- strtoupper() : convert the case of string into uppercase.
- strtolower() : convert the case of string into lowercase.
- substr() : return a sub string from a string of a length and from starting position.
- trim() : removes the white spaces from a string from left and right.
- ucfirst() : convert the case of first letters of all words in a string to uppercase.
- wordwrap() : break lines after a length.
- print() : output the result string when passed to it.
- print_r() : prints a resources ,object or an array along with the indexes.
- unlink() : delete a file from its location.
- unset() : set the value of a variable undefined.
- isset() : check whether the variable is defined or not.
- empty() : check whether an array is empty.
- array_chunk() : breaks an array into chunks of small arrays.
- array_combine() : combine two arrays of equal size where one is used for keys and another one is used for values.
- array_count_values() : count and returns the number of values of an array
- array_diff() : returns an array having difference between two arrays.
- array_flip() : flip key and value simultaneously.
- array_filter() : filter the values of an array based on a callback function.
- array_key_exists() : returns true if a key exists in an array.
- array_keys() : returns the array of keys from an array.
- array_map() : apply some operation on each value of an array and return a new array with modified values.
- array_merge() : merge the values of two array while retaining their keys.
- array_merge_recursive() : merge multidimensional arrays.
- array_push() : add a new value in an array at the end.
- array_rand() : select some random keys from an array.
- array_replace() : replace values in an array from the values in another array.
- array_reverse() : reverse the order of array and return new array.
- array_search() : search a value in an array and return the key of the value.
- array_shift() : remove the first element in an array.
- array_sum() : sum up all the values in an array.
- array_unique() : remove all the replicated values in an array.
- array_values() : returns an array of values with numeric index.
- array_walk() : Go to each value and run over an user defined function.
- array_walk_recursive() : Does the same recursively for an array.
- compact() : The compact() function creates an array from variables and their values.
- asort() : Sort an array values in ascending order.
- arsort() : Sort an array values in descending order.
- in_array() : returns true if a value find in an array.
- key() : return the key from the current pointer position.
- krsort() : sort and array based on keys and in descending order.
- ksort() : sort and array based on keys and in ascending order.
- range() : create an array from the range passed to it.
- date_create() : create a new date-time object.
- date_create_from_format() : Create a user defined date from given format.
- date_diff() : returns difference between two dates.
- date_sub() : subtracts some period of time from a given date.
- date() : output the current date and time based on parameters given to it.
- gettimeofday() : output current time.
- gmmktime() : output UNIX time for GMT.
- localtime() : returns local time as UNIX timestamp.
- strtotime() : convert a string having date-time information into UNIX date.
- time() : eturn the current time.
- ceil() : returns the next integer value of the floating number passed to it.
- floor(): returns the next lowest integer value
- abs() : returns the absolute value passed to it.
- base_convert() : convert the base of number system.
- is_nan() : check whether a value is Not a Number.
- is_infinite() : check whether a value is Infinite.
- max() : find the max value from an array.
- min() : find minimum value from an array.
- mt_rand() : based on Mersenne Twister Algorithm creates a random number.
- rand() : generate a random number
- round() : returns a floating point number up to a particular place of decimal point.
- sqrt() : returns the square root of the value passed to it.