PHP Interview Questions & Answers part 4

0
492
Q: – Why is it useful to know the type of data a variable holds?

Often the data type of a variable constrains what you can do with it. For example, you can't perform array-related functions on simple strings. Similarly, you may want to make sure that a variable contains an integer or a float before using it in a mathematical calculation, even though PHP will often help you by changing types for you in this situation.

Q: – How do you open a directory for reading?

opendir() function

Q: – What function do you use to read the name of a directory item after you've opened a directory for reading?

readdir()

Q: – What function do you use to read a line of data from a file?

fgets()

Q: – How can you tell when you've reached the end of a file?

feof()

Q: – Should I obey any conventions when naming variables?

Your goal should always be to make your code easy to read and understand. A variable such as $ab123245 tells you nothing about its role in your script and invites typos. Keep your variable names short and descriptive. A variable named $f is unlikely to mean much to you when you return to your code after a month or so. A variable named $filename, on the other hand, should make more sense.

Q: – What function do you use to write a line of data to a file?

fputs() function

Q: – Which function is used to open a pipe to a process?

popen()

Q: – Which of the following variable names is not valid? And why?

$a_value_submitted_by_a_user
$666666xyz
$xyz666666
$_____counter_____
$the first
$file-name

The variable name $666666xyz is not valid because it does not begin with a letter or an underscore character

Submitted By:-Payal Gupta            Email-ID: – payalgupta1325@yahool.com

SHARE

LEAVE A REPLY