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

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

81) What does in_arry function do?

When any word or string is to be searched in any array, we use in_array function. It retunes boolean value.
Example :

$str=”Hello”;
$arr= array(‘Hello’,’Bye’,’Hi’);
$rslt= in_array($str,$arr);

82) Which is the two frequently and important string operators?

a). Concatenation (.) operator : This operator is used for combining more than one strings or variables.
b). = assignment operator : This operator is used assign right side value to left side variable.

83) Where we use ‘===’ operator?

When we have to check if the two variables are of same value and same type, we use ‘===’. In another word, it’sused forstrict type checking.

84) How you can open a file in read-only mode in PHP?

To open the file in read only mode, first the fopen() function needs to be used for opening the file. It needs two arguments stating first the file name and then mode in which to operate. “r” mode opens the file for reading only and places the file pointer at the beginning of the file.

85) What is use of instanceof variable?

Using this variable we can check whether the PHP variable is an instantiated object of a certain class or not. It returns Boolean value.

86) How preg_match() function works?

preg_match() is PHP’s regular expressionfunction which is used for finding a string on the basis of given parameter. If the match is found, then value is returned true else false.

87) What isto_String() ?

When we try to print any object directly,we get cannot convert class to string.
If we use _toString() before function name, now echoing the object is possible.
Example :

class Assets{

protected
$queue = array();

public function add($script){
$this->queue[] = $script;
}

public function __toString(){
$output = ”;
foreach($this->queue as $script){
$output .= ‘‘;
}
return $output;
}

}

$scripts = new Assets();

echo $scripts

88) How will you get the current date and time using PHP?

time() function provides complete information about current date and time.

89) If PHP Error is disabled from php.ini then how you can still show that in any specific page?

ini_set(‘display_errors’, 1);
error_reporting(E_ALL ^ E_NOTICE);

90) How to check if the variable is set or not?

PHP’s isset function is used to check if the variable is set or not.

91) What is the difference between the functions strstr() and stristr()?

Both are string functions of PHP. When strstr() is is applied with argument and the argument matches with the string, it displays rest of the string text from there.
Example :

Output : World!
Both are same except that stristr is case in-sensetive while strstr is case sensitive.

92.What is difference between while loop and do while loop?

In while Loop condition is checked first and then displays the result. So, in this case if the condition is false, it does now show any result.

93) What is interfaces?

Interfaces are defined for common pattern. In interfaces only the variables are decaled and not implemented. The implementing class function will use the pattern.
Interfaces are defined same way as class except interface keyword instead of class keyword.

94) What is the difference between ereg_replace() and eregi_replace()?

Both regular expression functions of PHP. The difference is that the function eregi_replace() is not case sensitive while ereg_replace() is case sensitive.

95) What is ereg() and eregi() functions?

ereg() function takes two parameter, in the first parameter regular expression string pattern is used and in the second parameter, the string. If the pattern matches with the string, it returns true or else false.
ereg() and eregi() both are identical except that ereg is not case sensitive while ereg is case sensitive.

96) Mention 3 main error types in PHP

Though, there are several types of errors in PHP but the main ones are notices, warnings and fatal errors. If there is warning and notices in the file, the program can still run, but if there is fatal error, program stops executing.

97) How will you retrieve source filename using Exception class in PHP when error occured?

Using getFile() method of Exception class which returns source filename.

96) How can you delete cookies?

Simply changing the date of the cookie to thepast date causes the cookie to expire.

98) How to check if the table is already created?

IF NOT EXISTS is used to check if the table already created or not.

99) How URL e-write is possible?

URL re-writing is possible through htaccess. URL re-writing is feature of apache and it must be enabled on the server.

100) What will be the result?

a) $x = 10;
echo $x++. ‘ ‘.$x;

b) $y = 10;
echo ++$y

echo ++$y. ‘ ‘ .$y;

Answer: a)The result is 10 and 11
b) 11 and 11

101) In which format image data is saved into MySql?

Image data is saved in MySql in blog data type