Journal

PHP Interview question and answers.

PHP Interview question and answers for experienced.

Question: What is the difference between unset() and unlink() ?
Answer: unset() sets a variable to “undefined” while unlink() deletes a file we pass to it from the file system.

Question: Can the value of a constant change during the script’s execution?
Answer: No, the value of a constant cannot be changed once it’s declared during the PHP execution.

Question: How would you declare a function that receives one parameter name hello?
Answer: If hello is true, then the function must print hello, but if the function doesn’t receive hello or hello is false the function must print bye.
Example:
<?php
function showMessage($hello=false){
  echo ($hello)?'hello':'bye';
}
?>

Question: The value of the variable input is a string 1,2,3,4,5,6,7. How would you get the sum of the integers contained inside input?
Answer: There is no unique answer to this question, but the answer must be similar to this one.You can use explode function.
Example:
<?php
echo array_sum(explode(',',$input));
?>

Question: How can we know the number of days between two given dates using PHP?
Answer:
<pre>$date1 = date(‘Y-m-d’);
$date2 = ’2006-07-01′;
$days = (strtotime() &ndash; strtotime()) / (60 * 60 * 24);
echo “Number of days since ’2006-07-01′: $days”;</pre>

Question: What are the differences between DROP a table and TRUNCATE a table?
Answer:
DROP TABLE table_name – This will delete the table and its data.
TRUNCATE TABLE table_name – This will delete the data of the table, but not the table definition.

Question: What are the differences between mysql_fetch_array(), mysql_fetch_object(), mysql_fetch_row()?
Answer:
mysql_fetch_array:
Fetch a result row as an associative array and a numeric array.

mysql_fetch_object:
Returns an object with properties that correspond to the fetched row and moves the internal data pointer ahead. Returns an object with properties that correspond to the fetched row, or FALSE if there are no more rows.

mysql_fetch_row():
Fetches one row of data from the result associated with the specified result identifier. The row is returned as an array. Each result column is stored in an array offset, starting at offset 0.

Ad comes here
Comments
Leave A Comment
PHP blog