100 PHP’s possible interview questions and answers for fresher-part 3

  • Home -
  • 100 PHP’s possible interview questions and answers for fresher-part 3

41) Where does the session values are stored?

Session values are stored on server but its records are kept through cookies.

42) What is the string function for escaping data before storing it in the database?

The addslashes function is used to escape data before storing into the database.

43) What string function do we use for removing escape characters?

The stripslashes function is used for removing the escape characters before apostrophes in a string.

44) What is difference between ‘asort’ and ‘ksort’

‘asort’ sorts the array by its value in ascending order. On the other hand, ‘ksort’ displays the data by its keys.

45) What is ‘push’ and ‘pop’ function used for?

Push function of array is used for inserting new elements into array. And ‘pop’ function of array is used for taking out last element of the array.

46) How can we remove HTML tags from the data?

The strip_tags() function is used to remove all the html tags from the data.

47) What is ‘protected’ keyword? And what is it used for?

When any data member (variable or function) is declared as ‘protected’ that means these data members can be inherited by its child class only. First the data members have to bring into child class then it can be accessed outside.

48) What is the static variable? What is its advantage?

When a variable is declared as static, its value is retained and not destroyed/overwritten like normal variable. Normally it’s declared inside any function. So when function is called more than one time, its value is retained from the first one.

Example:
functioncallme(){
$a=10;
$a++;
}
callme()
output:1
callme();
output:2

49) What is difference between local and global variable?

When a variable is declared outside the function, it’s called global variable and when a function is decaled inside a function, it’s called local variable.

50)How global variable cab ne accessed inside any function?

We have to use ‘GLOBAL’ keyword before that variable inside function, and then it can be accessed inside the function.

51) What is static class in PHP?

When a class is declared static that means its data members can be accessed without creating the object of that class.

52) Where is usedencType in PHP?

enctype=”multipart/form-data” is actually HTML code and it’s used in any form. It’s an encoding and before sending any file this encoding has to be done. Without encoding file upload is not possible.So, multipart/form-data is used when a form requires binary data.

53) What is associative array?

The array in which keys and values both are defined then it’s called associative array.

54) Is it possible to pass a variable by reference in PHP?

To pass a variable by reference, an ampersand sign is used in front of the variable.
$var1 = &$var2
Now, $var1 will hold the address of variable $var2

55) If we compare 100 to “100” so are both same in PHP?

In PHP thereis feature called internal typecasting where PHP comprehend the ‘type’ and changes into that data type.

$a=20;
$b=”20″;
if($a==$b){
echo “Yes! Both are equal”;
}
else{
echo “No both are not equal”;
}
Output will be: yes! Both are equal.

56) What is ‘count’ and ‘sizeof’ function used for?

Both ‘count’ and ‘sizeof’ are used for counting the number of array elements.

57) If we provide the input in switch statement which does not match with any one of the section then which part of switch control statement displays the message?

In switch case, if we provide wrong value, the value which is not specified, then we the ‘default:’ control statement of switch case displays the value.

58) What is use of ternary operator in PHP?

Ternary operator is the operator which is written in single line statement. It’s concise form of if else.
We write like this echo $val= $a>$b? “A is greater than B”:”B is greater than A”;

59) What is use of ‘substr’ function in PHP?

substr is a function which is used to display the truncated version of the text.
Its written like :substr($string,start_limit,end_limit). Say if start point is 0 and end LIMIT is 200 then it will display 200 characters.

60) What are constructor and destructor in PHP?

Constructor is a special function whose name is same as class name. The benefit of the constructor is that when an object of the class is created, it gets called automatically. It does not have to call separately. The ‘destructor’ method is called as soon as there are no other references to a particular object.