PHP Interview Questions with Answers - Part 1
PHP Interview Questions - Here are some of the best PHP Interview Questions with Answers. This is a platform where you can get everything about PHP Interview Questions & Answers.
1) What is the difference between strstr & stristr?
For strstr, the syntax is: string strstr(string $string,string $str ); The function strstr will search $str in $string. If it finds the string means it will return string from where it finds the $str upto end of $string.
$string = "http://yahoomail.com";
The output is "yahoomail.com". The main difference between strstr and stristr is of case sensitivity. The former consider the case difference and later ignore the case difference.
2) What is the difference between explode and split?
Split function splits string into array by regular expression. Explode splits a string into array by string.
explode(" and", "India and Pakistan and Srilanka");
split(" :", "India : Pakistan : Srilanka");
Both of these functions will return an array that contains India, Pakistan, and Srilanka.
3) How can you avoid execution time out error while fetching record from MySQL?
set_time_limit -- Limits the maximum execution time
If you set to 0 you say that there is not limit.
4) Write a SQL query that displays the difference between the highest and lowest salaries of a database table "employees". Label the column as DIFFERENCE.
Select max(sal)-min(sal) as Difference from employees;
5) What is the difference between require() and include()?
Both of these constructs includes and evaluates the specific file. The two functions are identical in every way except how they handle failure. If filepath not found, require() terminates the program and gives fatal error, but include() does not terminate the program; It gives warning message and continues to program.
include() produces a Warning while require() results in a Fatal Error if the filepath is not correct.
6) What is the difference between echo and print?
Main difference between echo() and print() is that echo is just an statement not a function and doesn’t return’s value or it just prints a value whereas print() is an function which prints a value and also it returns value.
We cannot pass arguments to echo since it is just a statement whereas print is a function and we can pass arguments to it and it returns true or false. print can be used as part of a more complex expression whereas echo cannot. echo is marginally faster since it doesn’t set a return value.
7) An examiner awards the highest mark 75 and the lowest mark 25, the pass marks being 40. The moderator wants to change the highest mark to 250 and the lowest marks to 100 using the linear formula y=ax+b. The revised pass marks will be:
Give the correct option.
Solve it get and b and then put
8) A and B are shooters and having their exam. A and B fall short of 10 and 2 shots respectively to the qualifying mark. If each of them fired at least one shot and even by adding their total score together, they fall short of the qualifying mark, what is the qualifying mark?
As A is short by 10 - he has shot 1
As B is short by 2 - he has shot 9
9+1=10 and 10
9) In objective test a correct answer score 4 marks and on a wrong answer 2 marks. A student scores 480 marks from 150 questions. How many answers were correct?
Answer: B i.e. 130
Then X is 130 so 130 is correct answer.
10) An INK bug starts jumping 1 meter to each direction north, south, east and west respectively. It marks a point in the new locations. It comes back to its original point after jumping in all directions. It again starts the same process from the newly drawn unique points. Totally how many points did the bug mark?
11) A guy walks at 4 mph from a point. After 4 hrs a cyclist starts from the same point at 10 mph. At what distance will they meet from the starting point?
Answer: 26.66 m
Explanation: We have, s=vt where s=distance. Since both meet at same point, both travels same distance=s km. Now, equating, 10(t+4) = 4t ------> t=20/3
sub. t=20/3 in s=4t---------> s = 26.66km
12) What’s the difference between COPY OF A FILE & MOVE_UPLOAD_FILE in file uploading?
Move: This function checks to ensure that the file designated by filename is a valid upload file (meaning that it was uploaded via PHP’s HTTP POST upload mechanism). If the file is valid, it will be moved to the filename given by destination.
If filename is not a valid upload file, then no action will occur, and move_uploaded_file() will return FALSE.
Copy: Makes a copy of a file. Returns TRUE if the copy succeeded, FALSE otherwise.
13) How do you insert single & double quotes in MySQL db without using PHP?
& / "e;
Alternately, escape single quote using forward slash ’ . In double quote you don’t need to escape quotes. Insert double quotes as "".
14) What do you need to do to improve the performance of the script you have written?
If your script is to retrieve data from Database, you should use "Limit" syntax. Break down the non dynamic sections of website which need not be repeated over a period of time as include files.
15) How do you capture audio/video in PHP?
You need a module installed - FFMPEG. FFmpeg is a complete solution to record, convert and stream audio and video. It includes libavcodec, the leading audio/video codec library. FFmpeg is developed under Linux, but it can be compiled under most operating systems, including Windows.
16) How do you know whether the recipient of your mail had opened the mail i.e. read the mail?
Embed an URL in a say 0-byte image tag may be the better way to go. In other word, you embed an invisible image on you html email and when the src URL is being rendered by the server, you can track whether your recipients have view the emails or not.
17) What is random number?
A random number is a number generated by a process, whose outcome is unpredictable, and which cannot be sub sequentially reliably reproduced.
18) What is difference between srand & shuffle?
The srand function seeds the random number generator with seed and shuffle is used for shuffling the array values.
shuffle - This function shuffles (randomizes the order of the elements in) an array. This function assigns new keys for the elements in array. It will remove any existing keys you may have assigned, rather than just reordering the keys.
srand - Seed the random number generator
19) How can we remove duplicate values from an array?
array_unique() funciton can be used for the purpose.
20) How do I find out weather a number is odd or even?
if (number%2==0 ) then even else odd.
21) How can we get the ID generated from the previous insert operation?
SELECT MAX(ID) from tablename;
22) How to limit the number of rows to 5 that I get out of my database?
Select * from tablename LIMIT 0, 5;
23) How to store binary data in MySQL?
Use BLOB data type for the database field.
24) How can we submit a form without a submit button?
25) How can I maintain the count of how many persons have hit my site?