|
|
|
The General Php Interview Questions consists the most frequently asked
questions in Php. This list of 100+ questions guage your familiarity with
the Php platform. The q&a have been collected over a period of time
from various blogs, forums and other similar Php sites
|
|
|
| 2.1 What is the
difference between the functions unlink and unset?
|
| 2.2 How come
the code works, but doesn’t for two-dimensional array of mine?
|
| 2.3 How can we
register the variables into a session?
|
| 2.4 What is the
difference between characters \023 and \x23?
|
| 2.5 With a
heredoc syntax, do I get variable substitution inside the heredoc contents?
|
| 2.6 How can we
submit form without a submit button?
|
| 2.7 How can we
create a database using PHP and mysql?
|
| 2.8 How many
ways we can retrieve the date in result set of mysql using php?
|
| 2.9 Can we use
include ("abc.php") two times in a php page "makeit.php"?
|
| 2.10 What’s
the output of the ucwords function in this example?
|
| 2.11 WHow can
we extract string "abc.com" from a string
"mailto:info@abc.com?subject=Feedback" using regular expression of PHP?
|
| 2.12 -So if
md5() generates the most secure hash, why would you ever use the less secure
crc32() and sha1()?
|
| 2.13 How can
we destroy the session, how can we unset the variable of a session?
|
| 2.14 What are
the different functions in sorting an array?
|
| 2.15 WHow can
we know the count/number of elements of an array?
|
| 2.16 How many
ways we can pass the variable through the navigation between the pages?
|
| 2.17 What is
the maximum length of a table name, a database name, or a field name in MySQL?
|
| 2.18 How many
values can the SET function of MySQL take? sss
|
| 2.19 What are
the other commands to know the structure of a table using MySQL commands except
EXPLAIN command?
|
| 2.20 How can
we find the number of rows in a table using MySQL?
|
2.1 What is the difference between the functions unlink and unset?
|
|
unlink() is a function for file system handling. It will simply delete the file
in context.
unset() is a function for variable management. It will make a variable
undefined.
|
|
2.2 How come the code works, but doesn’t for two-dimensional array of mine?
|
|
Any time you have an array with more than one dimension, complex parsing syntax
is required. print "Contents: {$arr[1][2]}" would’ve worked.
|
2.3 How can we register the variables into a session?
|
|
session_register($session_var);
$_SESSION['var'] = 'value';
|
2.4 What is the difference between characters \023 and \x23?
|
|
The first one is octal 23, the second is hex 23.
|
2.5 With a heredoc syntax, do I get variable substitution inside the heredoc
contents?
|
|
Yes.
|
2.6 How can we submit form without a submit button?
|
|
We can use a simple JavaScript code linked to an event trigger of any form
field. In the JavaScript code, we can call the document.form.submit() function
to submit the form. For example:
|
2.7 How can we create a database using PHP and mysql?
|
|
We can create MySQL database with the use of mysql_create_db($databaseName) to
create a database.
|
2.8 How many ways we can retrieve the date in result set of mysql using php?
|
|
As individual objects so single record or as a set or arrays.
|
2.9 Can we use include ("abc.php") two times in a php page "makeit.php"?
|
|
Yes.
|
2.10 What’s the output of the ucwords function in this example?
|
|
$formatted = ucwords("FYICENTER IS COLLECTION OF INTERVIEW QUESTIONS"); print
$formatted; What will be printed is FYICENTER IS COLLECTION OF INTERVIEW
QUESTIONS. ucwords() makes every first letter of every word capital, but it
does not lower-case anything else. To avoid this, and get a properly formatted
string, it’s worth using strtolower() first.
|
2.11 How can we extract string "abc.com" from a string
"mailto:info@abc.com?subject=Feedback" using regular expression of PHP?
|
|
$text = "mailto:info@abc.com?subject=Feedback";
preg_match('|.*@([^?]*)|', $text, $output);
echo $output[1];
|
2.12 So if md5() generates the most secure hash, why would you ever use the
less secure crc32() and sha1()?
|
|
Crypto usage in PHP is simple, but that doesn’t mean it’s free. First off,
depending on the data that you’re encrypting, you might have reasons to store a
32-bit value in the database instead of the 160-bit value to save on space.
Second, the more secure the crypto is, the longer is the computation time to
deliver the hash value. A high volume site might be significantly slowed down,
if frequent md5() generation is required.
|
2.13 How can we destroy the session, how can we unset the variable of a
session?
|
|
session_unregister() - Unregister a global variable from the current session
session_unset() - Free all session variables
|
2.14 What are the different functions in sorting an array?
|
|
Sorting functions in PHP:
asort()
arsort()
ksort()
krsort()
uksort()
sort()
natsort()
rsort()
|
2.15 How can we know the count/number of elements of an array?
|
|
2 ways:
a) sizeof($array) - This function is an alias of count()
b) count($urarray) - This function returns the number of elements in an array.
Interestingly if you just pass a simple var instead of an array, count() will
return 1.
|
2.16 How many ways we can pass the variable through the navigation between the
pages?
|
|
At least 3 ways:
1. Put the variable into session in the first page, and get it back from
session in the next page.
2. Put the variable into cookie in the first page, and get it back from the
cookie in the next page.
3. Put the variable into a hidden form field, and get it back from the form in
the next page.
|
2.17 What is the maximum length of a table name, a database name, or a field
name in MySQL?
|
|
Database name: 64 characters
Table name: 64 characters
Column name: 64 characters
|
2.18 Can I How many values can the SET function of MySQL take?
|
|
MySQL SET function can take zero or more values, but at the maximum it can take
64 values
|
2.19 What are the other commands to know the structure of a table using MySQL
commands except EXPLAIN command?
|
|
DESCRIBE table_name;
|
2.20 How can we find the number of rows in a table using MySQL?/h2>
|
|
Use this for MySQL
SELECT COUNT(*) FROM table_name;
|
|