PHP Interview & Certification Questions with answers

1.What is defined in PHP?

Checks whether the given constant exists and is defined. Note: If you want to see if a variable exists, use isset() as defined() only applies to constants.

If you want to see if a function exists, use function_exists().

PHP programming 25 Best + Free Online certification courses

2.What is PHP and why it is used?

PHP (Hypertext Preprocessor) is known as a general-purpose scripting language that can be used to develop dynamic and interactive websites.

It was among the first server-side languages that could be embedded into HTML, making it easier to add functionality to web pages without needing to call external files for data.

3.What are PHP functions?

A function is a piece of code that takes another input in the form of a parameter, processes it, and then returns a value.

A PHP Function feature is a piece of code that can be used over and over again and accepts argument lists as input, and returns a value.

PHP comes with thousands of built-in features.

4.How can we define constant in PHP?

A constant is an identifier (name) for a simple value. The value cannot be changed during the script.

A valid constant name starts with a letter or underscore (no $ sign before the constant name).

Note: Unlike variables, constants are automatically global across the entire script.

5.What type of language is PHP?

The PHP Programming Language Meaning Explained. PHP is an open-source server-side scripting language that many devs use for web development.

It is also a general-purpose language that you can use to make lots of projects, including Graphical User Interfaces (GUIs).

6.What is type of function in PHP?

Types of Functions in PHP. There are two types of functions as:

7.Is variable defined PHP?

The isset() function checks whether a variable is set, which means that it has to be declared and is not NULL.

This function returns true if the variable exists and is not NULL, otherwise it returns false.

8.Why PHP is called scripting language?

PHP is Scripting language because we can embed php code into HTML.

If code of programming language can emmbed with other language or integrate with other language or script called scipting language.

PHP is server side language because php requires server to run a code.

9. What is PHP application?

PHP is an open source scripting language that can be used to write websites and any kind of web-based application and service.

Wikipedia, Vimeo, Etsy, Mailchimp, Yahoo, Wordpress, Flickr, and Magento are just a few of the commercial web apps written in the language.

10.What is a PHP database?

PHP is a server-side, HTML-embedded scripting language that may be used to create dynamic Web pages.

It is available for most operating systems and Web servers, and can access most common databases, including MySQL.

PHP may be run as a separate program or compiled as a module for use with a Web server.

11.What are the characteristics of PHP?

12.What is PHP and HTML?

PHP is a scripting language | HTML is a markup language.

PHP code is executed on the server | HTML code is parsed by the client browser.

PHP creates dynamic web pages | HTML creates static web pages.

PHP can access a database | Database cannot be accessed using HTML.

13.What are PHP arrays?

An array is a special variable that we use to store or hold more than one value in a single variable without having to create more variables to store those values.

To create an array in PHP, we use the array function array( ).

By default, an array of any variable starts with the 0 index.

14.What is the class in PHP?

Class is a programmer-defined data type, which includes local methods and local variables.

Class is a collection of objects. Object has properties and behavior.

15.What are the different data types of PHP?

PHP supports the following data types:

16.How many types of function are there in PHP?

PHP has over 1000 built-in functions that can be called directly, from within a script, to perform a specific task.

Please check out our PHP reference for a complete overview of the PHP built-in functions.

17.What is a string in PHP?

PHP string is a sequence of characters i.e., used to store and manipulate text.

PHP supports only 256-character set and so that it does not offer native Unicode support.

There are 4 ways to specify a string literal in PHP. single quoted.

18.What is a static variable in PHP?

The static keyword is used to declare properties and methods of a class as static.

Static properties and methods can be used without creating an instance of the class.

The static keyword is also used to declare variables in a function which keep their value after the function has ended.

19.What is Boolean data type in PHP?

This is one of the scalar data types in PHP.

A boolean data can be either TRUE or FALSE.

These are predefined constants in PHP. The variable becomes a boolean variable when either TRUE or FALSE is assigned.

20.What are the different types of array in PHP?

In PHP, there are three types of arrays:

21.Is PHP a good language?

It is considered a very effective technology that offers a convenient development process with many additional tools to aid it.

In fact, according to the Popularity of Programming Language Index (PYPL), PHP is the fifth most popular coding language in the world.

22.Is PHP a backend language?

PHP is a back end development language only. PHP belongs to the LAMP stack, which stands for Linux, Apache, MySQL, and PHP/Perl/Python.

To develop a web app with this technology stack, a software engineer needs to know four different syntax systems, as well as HTML and CSS.

23.Is NULL in PHP?

The is_null() function checks whether a variable is NULL or not.

This function returns true (1) if the variable is NULL, otherwise it returns false/nothing.

24.Is a number PHP?

The is_numeric() function checks whether a variable is a number or a numeric string.

This function returns true (1) if the variable is a number or a numeric string, otherwise it returns false/nothing.

25.What is empty PHP?

The empty() function checks whether a variable is empty or not.

This function returns false if the variable exists and is not empty, otherwise it returns true. The following values evaluates to empty: 0. 0.0.

26.Is PHP same as SQL?

SQL - Structured Query language is the standard language for relational database management systems.

PHP is a general-purpose and sever scripting language. It is used for making dynamic and interactive web pages.

27.What is the basic syntax of PHP?

A PHP script can be placed anywhere in the document.

The default file extension for PHP files is " .php ". A PHP file normally contains HTML tags, and some PHP scripting code.

28.How do I code in PHP?

After saving your code file into the htdocs folder follow the below steps:

29.Why echo is used in PHP?

They are both used to output data to the screen.

The differences are small: echo has no return value while print has a return value of 1 so it can be used in expressions.

Echo can take multiple parameters (although such usage is rare) while print can take one argument. echo is marginally faster than print .

30.What is printf in PHP?

The printf() function outputs a formatted string.

The arg1, arg2, ++ parameters will be inserted at percent (%) signs in the main string.

This function works "step-by-step". At the first % sign, arg1 is inserted, at the second % sign, arg2 is inserted, etc.

31.What is return value in PHP?

The return keyword ends a function and, optionally, uses the result of an expression as the return value of the function.

If return is used outside of a function, it stops PHP code in the file from running.

32.What is a variable in PHP?

A variable can have a short name (like x and y) or a more descriptive name (age, carname, total_volume).

Rules for PHP variables:

A variable starts with the $ sign, followed by the name of the variable.

A variable name must start with a letter or the underscore character.

A variable name cannot start with a number.

33.What are constants in PHP?

A constant is an identifier (name) for a simple value.

The value cannot be changed during the script.

A valid constant name starts with a letter or underscore (no $ sign before the constant name).

Note: Unlike variables, constants are automatically global across the entire script.

34.How do I run a PHP file?

php” file is placed inside the “htdocs” folder. If you want to run it, open any web browser and enter “localhost/demo. php” and press enter. Your program will run.

35.What is open source in PHP?

Open source is a term that originally referred to open source software (OSS).

Open source software is code that is designed to be publicly accessible—anyone can see, modify, and distribute the code as they see fit.

36.What is MySQL in PHP?

MySQL is a database system used on the web.

MySQL is a database system that runs on a server. MySQL is ideal for both small and large applications.

MySQL is very fast, reliable, and easy to use. MySQL uses standard SQL.

37.What is PHP most frequently used for?

PHP(short for Hypertext PreProcessor) is the most widely used open source and general purpose server side scripting language used mainly in web development to create dynamic websites and applications.

38.How does HTML interact with PHP?

If you want to represent web-pages, you need to use HTML markup.

PHP is merely a programming language which is (in this context) used to dynamically generate HTML markup.

So, if you request a PHP file, and expect a web-page in return, the PHP script has to generate the HTML markup and send it in the response.

39.What are the popular frameworks in PHP?

40.What is the use of count() function in PHP?

The PHP count() function is used to count total elements in the array, or something an object.

41.What is the use of header() function in PHP?

The header() function is used to send a raw HTTP header to a client. It must be called before sending the actual output. For example, you can't print any HTML element before using this function.

42.What is PEAR in PHP?

PEAR is a framework and repository for reusable PHP components.

PEAR stands for PHP Extension and Application Repository.

It contains all types of PHP code snippets and libraries.

It also provides a command line interface to install “packages” automatically.

43. What is the meaning of ‘escaping to PHP’?

The PHP parsing engine needs a way to differentiate PHP code from other elements in the page.

The mechanism for doing so is known as ‘escaping to PHP’.

Escaping a string means to reduce ambiguity in quotes used in that string.

44.What is the purpose of break and continue statement?

Break:It terminates the for loop or switch statement and transfers execution to the statement immediately following the for loop or switch.

Continue:It causes the loop to skip the remainder of its body and immediately retest its condition prior to reiterating.

45.Name some of the functions in PHP?

ereg() – The ereg() function searches a string specified by string for a string specified by pattern, returning true if the pattern is found, and false otherwise.

split() – The split() function will divide a string into various elements, the boundaries of each element based on the occurrence of pattern in string.

preg_match() – The preg_match() function searches string for pattern, returning true if pattern exists, and false otherwise.

preg_split() – The preg_split() function operates exactly like split(), except that regular expressions are accepted as input parameters for pattern.

46.What is the difference between $message and $$message in PHP?

They are both variables. But $message is a variable with a fixed name.

$$message is a variable whose name is stored in $message.

For example, if $message contains “var”, $$message is the same as $var.

47.How can we create a database using PHP and MySQL?

The basic steps to create MySQL database using PHP are:

Establish a connection to MySQL server from your PHP script.

If the connection is successful, write a SQL query to create a database and store it in a string variable.

Execute the query.

48.List the main types of errors in PHP and explain their differences.

Notices: These are non-critical errors that can occur during the script execution. These are not visible to users. Accessing an undefined variable is an example of a 'Notice'.

Warnings:These are more critical than Notices, but just like them, Warnings don't interrupt the script execution. However, these are visible to the user by default. Example: include() a file that doesn't exist.

Fatal: This is the most critical error type which, when occurs, immediately terminates the script execution. Accessing a property of a non-existent object or require() a non-existent file is an example of this error type

49. Name and define the three scope levels available in PHP?