Skip to Content, PHP, MySQL, Javascript, Ajax, Htacces

PHP Interview Questions and Answers For Freshers part-5

Be First!

PHP41.How can you sort an array?
sort() − Sorts an array.

42.What is the difference between single quoted string and double quoted string?
Singly quoted strings are treated almost literally, whereas doubly quoted strings replace variables with their values as well as specially interpreting certain character sequences.

$variable = “name”;
$literally = ‘My $variable will not print!\\n’;
print “<br />”;
$literally = “My $variable will print!\\n”;
This will produce following result −

My $variable will not print!\n
My name will print

43.How will you concatenate two strings?
To concatenate two string variables together, use the dot (.) operator.

$string1=”Hello World”;
echo $string1 . ” ” . $string2;
This will produce following result −

Hello World 1234

44.What is the use of $_REQUEST variable?
The PHP $_REQUEST variable contains the contents of both $_GET, $_POST, and $_COOKIE. We will discuss $_COOKIE variable when we will explain about cookies. The PHP $_REQUEST variable can be used to get the result from form data sent with both the GET and POST methods.

45.How will you include the content of a PHP file into another PHP file?
There are two PHP functions which can be used to included one PHP file into another PHP file.

The include() Function

The require() Function

46.What is the difference between include() Function and require() Function?
If there is any problem in loading a file then the require() function generates a fatal error and halt the execution of the script whereas include() function generates a warning but the script will continue execution.

47.How will you open a file in readonly mode?
The PHP fopen() function is used to open a file. It requires 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.

48.How will you read a file in php?
Once a file is opened using fopen() function it can be read with a function called fread(). This function requires two arguments. These must be the file pointer and the length of the file expressed in bytes.

49.How will you get the size of a file in php?
The files’s length can be found using the filesize() function which takes the file name as its argument and returns the size of the file expressed in bytes.

50.How will you check if a file exists or not using php?
File’s existence can be confirmed using file_exist() function which takes file name as an argument.



Leave a Reply