PHP Interview Questions & Answers part 6

Q: – Must I always surround a code block in a control statement with brackets?

If the code you want executed as part of a control structure consists of only a single line, you can omit the brackets. However, the habit of always using opening and closing brackets, regardless of structure length, is a good one.

Q: – Which PHP function do you use to format date information?


Q: – Which PHP function could you use to check the validity of a date?


Q: – How would you break up a delimited string into an array of substrings?

explode() function

Q: – Using PHP, how do you acquire a UNIX timestamp that represents the current date and time?

time() function

Q: –How would you create a while statement that increments through and prints every odd number between 1 and 49?

$num = 1;

while ($num <= 49) {
echo "$num<br>";
$num += 2;

Q: – Which PHP function accepts a timestamp and returns an associative array that represents the given date?

getdate() function

Q: – Which predefined variable do you use to find the name of the script?

The variable $_SERVER[‘PHP_SELF’] holds the name of the script.

Q: – What value will the following expression return?

5 < 2
What data type will the returned value be?
The expression will resolve to false, which is a Boolean value.

Submitted By:-Payal Gupta            Email-ID: –