PHP Interview Question Answer
1 - How to Convert Date to Unix time stamp and Unix time stamp to Date

strtotime()- Convert Date into Unix time stamp

<?php
echo(strtotime("now") . "<br>");
echo(strtotime("13 October 2018") . "<br>");
?>

Date()- Convert Unix time stamp to Date

<?php
$timestamp=1549974080;
echo date("Y-m-d", $timestamp);
?>

2 - What is default session time?

24 minutes(1440 seconds)

3 - What does array_count_values?

This function will counts all the values of an array

<?php
$a=array("Sunday","Monday","Sunday","Monday","Tuesday");
print_r(array_count_values($a));
?>

Output:
Array ( [Sunday] => 2 [Monday] => 2 [Tuesday] => 1 )

4 - Full Form of PHP Open source softwares

XAMPP stands for Cross-Platform (X), Apache (A), MySQL (M), PHP (P) and Perl (P)
WAMP stands for Windows (W), Apache (A), MySQL (M) and PHP(P)
LAMP stands for Linux (L), Apache (A), MySQL (M) and PHP(P)
MacOS stands for MacOS (M), Apache (A), MySQL (M) and PHP(P)

5 - Delete duplicate record

Delete Record based on Adhaar Card

DELETE n1 FROM tbl_user n1, tbl_user n2 WHERE n1.id > n2.id AND n1.adhaar_no = n2.adhaar_no

6 - What is the difference between unset() and unlink()?

unset() is sets a variable to undefined(means variable delete)
unlink() is use to delete file.

7 - What is array_combine()?

array_combine() function create an array by using keys and values. both array must be equal.

<?php
$index=array("A","B","C");
$value=array("50","40","50");
$result=array_combine($index,$value);
print_r($result);
?>

output-
Array ( [A] => 50 [B] => 40 [C] => 50 )

8 - Find Maximum value in Array without function

$myarray = array(45,78,42,48,55,23,98);
$currvalue = '';
$maxvalue = 0;

foreach($myarray as $value) {
$currvalue = $value;

if($currvalue >= $maxvalue) {
$maxvalue = $currvalue;
}
}

echo "greatest number is $maxvalue"; 

9 - List data types in PHP ?

integer
boolean
float
string
array
object
callable
resource
NULL

10 - What is the difference between == and === operator?

== equal operator is use to check two value is equal or not. If we use === operator then it will check two value is equal with same data type

11 - How Many column we can update?

we can update 64 columns in single mysql query

12 - Update Column based on condition

UPDATE users
SET is_subscribed = CASE WHEN is_subscribed = '1' THEN '0'
WHEN is_subscribed = '0' THEN '1'
ELSE is_subscribed END

13 - What is the Output of the following code?

<?php

echo 1+2+"D4";

?>

Output:
Warning: A non-numeric value encountered in C:\xampp\htdocs\shishir\test4.php on line 2
3

14 - what is the difference between include and include_once?

Include We include file many times in single script. Include_once This will include file only one time, second if we include this file this will be ignore

15 - How can we get the IP address of the client?

$_SERVER["REMORTE_ADDR"] Superglobal variable is use to get IP Address

16 - Mysql Query to Find 2nd hightest salary from the employee table

Query1
SELECT DISTINCT salary FROM emp ORDER by salary desc LIMIT 1,1

Query2
SELECT (salary) FROM emp GROUP BY salary DESC LIMIT 1,1

Query3
SELECT salary FROM emp
WHERE salary = (SELECT (salary) FROM emp GROUP BY salary DESC LIMIT 1,1)

All above these query doing same work.

17 - What are SQL Injections?

SQL Injections are a method to print SQL Statement in browser. Hacker easily get information etc.

18 - What is a Persistent Cookie?

A persistent cookie is permanently stored on Client computer this will create notepad file, But temporary cookie erased when we close broswer.

For Permanent cookie we use set_cookie()

For Temporary cookie we use $_SESSION[]

19 - PHP Code to Reverse Word in String

$str="I am proud to be Indian";

$length = 0;
while(@$str[$length]) {
$length++;
}


$endindex=$length-1;

for($i=$length-1;$i>=0;$i--){

if($str[$i]==' ' || $i==0){
if( $i==0)
{
$startindex=0;
}
else
{
$startindex=$i+1;
}
for($j=$startindex;$j<=$endindex;$j++){
echo $str[$j];
}

$endindex=$i-1;
echo " ";
}
}

20 - What is the output of the code?

<?php
$x = '71';
$y = &$x;
$y = "2$y";
echo $x;
?>


Output:
271

21 - What is encapsulation?

An act of combining properties and methods, related to the same object, is known as encapsulation

22 - When Import Data in phpmyadmin then Error show file size exceeded the maximum size permitted by your PHP configuration.

Follow theses steps

Open php.ini file

Search below code

; Maximum allowed size for uploaded files.
upload_max_filesize = 2M

we can change max 8M size here, then restart apache and mysql

23 - How can you take the backup and restore a MySQL database using PHP?

//To take the backup of database
mysqldump database > backup -file.sql;

//To restore the database
mysqldump database < backup -file.sql;

24 - Find value in Array without function

$myarray = array(45,78,42,48,55,23,98);
$searchstatus = 0;
$searchvalue = 564;

foreach($myarray as $value) {

if($searchvalue == $value) {
$searchstatus=1;
}
}

if($searchstatus==1)
echo "Value Found";
else
echo "Value Not Found";

25 - Swap two value without using third variable

Code 1

<?php
$a=5;
$b=6;
$a=$a+$b;
$b=$a-$b;
$a=$a-$b;
echo $a;
echo "<br>";
echo $b;
?>

Code 2

<?php
$a=5;
$b=6;
list($a,$b)=array($b,$a);
echo $a;
echo "<br>";
echo $b;
?>

26 - What is array_chunk()?

The array_chunk() function splits an array into chunks of new arrays.

<?php

$cars=array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
print_r(array_chunk($cars,3));
?>

Array (
[0] => Array ( [0] => Sunday [1] => Monday [2] => Tuesday )
[1] => Array ( [0] => Wednesday [1] => Thursday [2] => Friday )
[2] => Array ( [0] => Saturday )
)

Note: Above Example create array each contain 3 values. because we use ($cars,3).

27 - How can we remove HTML Tags from Data?

Strip_tags() function

28 - How can we define a constant PHP?

define() is use to define constant

Example
define ("Salary",5000);

29 - Difference between PHP5 and PHP7

1- In PHP7 New Spaceship Operator(<=>) Introduce

$a <=> $b;
Same as in PHP5 We use
$a>$b ? 1 : -1

<?php
$x=32;
$y=66;
echo $x>$y ? 1 : -1; //PHP5
echo $x<=>$y; //PHP7
?>

2- In php 5 we can use mysql_* and mysqli_*, but in php mysql_* functions are completely removed, we use mysqli_* only

3- asp style tags(<% %>) and script tag(<script language="php"></script>) removed.

4- Function parameter type and Return type is possible.

30 - What is the use of Final keyword?

The final keyword prevents child classes from overriding a method.

Example

class Base
{
final function add($x,$y)
{
$sum=$x+$y;
echo $sum;
}
}
class Derived extends Base
{
function add($x,$y)
{
$sum=$x+$y;
echo $sum;
}
}
$obj= new Base();
$obj->add(100,100);
?>

Output : Show error
Fatal error: Cannot override final method Base::show()

31 - What is the purpose of php.ini file?

php.ini is a default configuration file require for running application, we edit this as per our requirement
In xampp we can see this file on xampp->php->php.ini

Some php.ini setting we can do.

Increase memory limit
we can enable short tag
we can change max_execution_time
To enable or disable display error,log error,html error, log error ...
We can increase or decrease File uploading size
We can increase or decrease Maximum number of file upload
we can add/remove/comment extension like extension=php_mbstring.dll

32 - Import database into mysql by command line

mysql -u  root -h localhost mycv < F:\mycv.sql

 

Servername: localhost
Databasename: mycv
Filepath: F:\mycv.sql
Username: root
Password: (blank)

33 - Abstract Class in PHP

we can create object of the abstract class.Abstract method can't define in abstract class,Normal function we can define.if we want, the user must be define class method. so abstract class is usefull.abstract method be declare in abstract class.

34 - MySQL storage engines

InnoDB
MyISAM
Memory
CSV
Merge
Archive
Federated
Blackhole
Example

InnoDB is the most widely used storage engine with transaction support.

MyISAM is the original storage engine. It is a fast storage engine. It does not support transactions.

Memory storage engine creates tables in memory. It is the fastest engine.

CSV stores data in CSV files.

Merge operates on underlying MyISAM tables.

Archive storage engine is optimised for high speed inserting. It compresses data as it is inserted

The Blackhole storage engine accepts but does not store data. Retrievals always return an empty set.

Federated storage engine offers the ability to separate MySQL servers to create one logical database from many physical servers.


Next

Share on Facebook
Success Story
Sanjay Kumar
Avatar
Programmer
Falcon software PVT Ltd.
The string functions and HTML platform that we worked on for the PHP codes at IT and DC training institute gave us new avenues to explore and my current job is also due to the new faith in the subject and the knowledge that I have gained by exploring the grounds. I am happy that I joined this institute for the course.
Promod
Avatar
PHP Developer
IT&DC
My friends had advised me to go for the language courses for web development but I was scared that it was not my cup of tea. Then I started to get trained in the web development course under IT Training Online and saw that it is fun and interesting. Now I am very busy doing the web development of different companies as a freelancer and am doing well as a developer.
Sponsored Ads