Php Interview Questions

52 Qs

Check your knowlege about Php, and prepare for your next tech interview Php is one of the most used programming language and widely in demand for 2026

1
Fresher

What is the use of ini_set() ?

Answer

PHP allows the user to modify some of its settings mentioned in php.ini using ini_set(). This function requires two string arguments. The first one is the name of the setting to be modified and the second one is the new value to be assigned to it.

Given line of code will enable the display_error setting for the script if it’s disabled.

ini_set('display_errors', '1');

We need to put the above statement, at the top of the script so that, the setting remains enabled till the end. Also, the values set via ini_set() are applicable, only to the current script. Thereafter, PHP will start using the original values from php.ini.

2
Fresher

What is the difference between == and ===?

Answer
  • The operator == casts between two different types if they are different

  • The === operator performs a 'typesafe comparison'

That means that it will only return true if both operands have the same type and value.

1 === 1: true
1 == 1: true
1 === "1": false // 1 is an integer, "1" is a string
1 == "1": true // "1" gets casted to an integer, which is 1
"foo" === "foo": true // both operands are strings and have the same value
3
Fresher

What is the return type of a function that doesn't return anything?

Answer

void which means nothing.

4
Fresher

What is the purpose of the php.ini file?

Answer

The PHP configuration file, php.ini, is the final and most immediate way to affect PHP's functionality. The php.ini file is read each time PHP is initialized. in other words, whenever httpd is restarted for the module version or with each script execution for the CGI version.

5
Fresher

What are the keys & values in an indexed array?

Answer

Consider:

Array ( [0] => Hello [1] => world [2] => It's [3] => a [4] => beautiful [5] => day)

The keys of an indexed array are 0, 1, 2 etc. (the index values) and values are "Hello", "world", "It's", "beautiful", "day".

6
Fresher

What does $GLOBALS mean?

Answer

$GLOBALS is associative array including references to all variables which are currently defined in the global scope of the script.

7
Fresher

How can you pass a variable by reference in Php?

Answer

To be able to pass a variable by reference, we use an ampersand in front of it, as follows:

$var1 = &$var2
8
Fresher

Differentiate between echo and print()

Answer

echo and print are more or less the same. They are both used to output data to the screen.

The differences are:

  • 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 faster than print.

9
1+ yr

What does the 'var' keyword mean in PHP?

Answer

It's for declaring class member variables in PHP4 and is no longer needed. It will work in PHP5 but will raise an E_STRICT warning in PHP from version 5.0.0 up to version 5.1.2, as of when it was deprecated. Since PHP 5.3, var has been un-deprecated and is a synonym for 'public'.

Consider:

class foo {
    var $x = 'y'; // or you can use public like...
    public $x = 'y'; //this is also a class member variables.
    function bar() {
    }
}
10
1+ yr

What do we mean by keys and values?

Answer

In associative arrays, we can use named keys that you assign to them. There are two ways to create an associative array:

// first way -

$age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");`

// another method - 
$age['Peter'] = "35"; //Peter, Ben & Joe are keys
$age['Ben'] = "37"; //35, 37 & 43 are values
$age['Joe'] = "43";

More questions available

Sign in to get access to all questions, answers, and detailed explanations.