PHP Functions Interview Questions & Answers

PHP Functions Interview Questions & Answers list

Here, you can read about PHP Function related Interview Questions & Answers. This list contains popular & frequently asked interview questions and answers related to PHP Functions. Find PHP Functions FAQs for Job Preparation for freshers and experienced level.

What is PHP Function?

PHP Function is a set of statements that perform a specific task. A function usually takes input arguments, perform a specific action on them and returns the result.

Example of function in PHP:

Which PHP function can be used check if variable is an array?

PHP is_array() function is used to check, if a variable is an array or not. This is_array() function will return true, if a variable is an array or false if it is not.

What PHP Function is used to find position of a string?

PHP strpos() function is used to find the first occurrence of substring in the given string.

Output: 13

The word ‘apple’ is found at the position ’13’. Remember that the position of string/character start at 0, and not 1. This function is very useful to find certain patterns or words in a string.

What is the use of ucwords() PHP String function?

PHP ucwords() function is used to capitalized the first letter of each word in String.

Run :

What is the use of str_replace() PHP String function?

The PHP str_replace() function is used to search & replace some words in a strings.

In this example, “Hello” word will be replaced by “Hi” in the given string.

Run :

Can we include a file two times in any PHP page?

Yes, we can use include("sample.php") function more than once in any PHP page. It will include code from ‘sample.php’ file multiple times.

Note: If ‘sample.php’ file contains some functions declaration, there will be an error. Why? Because it will try to separate function with the same name again and it will throw an error.

Which is the PHP function to delete a file from server?

PHP has lots of inbuilt Functions. One of them is the unlink() PHP function which is used to delete a file from server. Example: unlink("sample-file.php")

What is PHP floor() function?

With the help of floor() function, we can convert a numeric value to the it’s next lower integer value.

Example of floor() function in PHP:

How to check if a variable is empty in PHP?

The empty() function is an in-built function in PHP which is used to check whether a variable is empty or not.

Example of empty function:

Here is the list of values, that are returned as an empty

  • “” (an empty string)
  • 0(as an integer)
  • 0.0(o as a float)
  • “0”(o as a string)
  • Null
  • False
  • array() (an empty array)

How to count the number of parameters passed in a PHP function?

With the help of func_num_args() function, we can count the number of parameters passed into a PHP function.

Example of function func_num_args():