Top 10 PHP Programming/ Logical Interview questions and answers

 Top 10 PHP Programming/ Logical Interview questions and answers

 

Online Learn  Top 10 PHP Programming/ Logical Interview questions and answers  :

outsource2global is the leader in technology around world. we provide online training training to become smart php developer . This is the   Latest Top 10 PHP Interview questions and answers For fresher. This tutorials helps you to crack the interview and get selected in Top Mnc Company.Please update on my website for latest question and answer that is asked by interviewer. Outsource2global provides this Top 10 PHP interview questions and answers for 1 year exprience.  we provide this tutorials in different different countries like USA,UK,CANADA,AUSTRALIA,NEW ZEALAND etc . Outsource2global is the leading brands for learning online PHP and become a smart developer .If you are looking to get more and more information . Please click here.

 

 

Top 10 PHP Programming/ Logical Interview questions and answers

 

 

Write a program for following output?

* * * * *
* * * *
* * *
* *
*

Answer –
<?php
for($k=0;$k<=5;$k++){
for($m=5-$i;$m>=1;$m–){
echo “*&nbsp;”;
}
echo “<br>”;
}
?>

Write a program for following  output?

*
* *
* * *
* * * *
* * * * *

Answer-
<?php
for($i=0;$i<=5;$i++){
for($j=1;$j<=$i;$j++){
echo “*&nbsp;”;
}
echo “<br>”;
}
?>

Write a program for following output?

*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * *
* * * *
* * *
* *
*

Answres-
<?php
for($i=0;$i<=6;$i++){
for($k=6;$k>=$i;$k–){
echo ” &nbsp;”;
}
for($j=1;$j<=$i;$j++){
echo “* &nbsp;”;
}
echo “<br>”;
}
for($i=5;$i>=1;$i–){
for($k=6;$k>=$i;$k–){
echo ” &nbsp;”;
}
for($j=1;$j<=$i;$j++){
echo “* &nbsp;”;
}
echo “<br>”;
}
?>

Write a program for following output?

*****
*****
*****
*****
*****

Answer-
<?php
for ($c=1; $c<=5; $c++)
{

for($c=1; $c<=5; $c++)
{
echo “*”;

}
echo “<br>”;
}
?>

 Find a factorial of a given  number ?

Answer-
<?php
if(isset($_POST[‘submit’]))
{
$number = $_POST[‘num’]; /*number to get factorial */
$fact = 1;
for($k=1;$k<=$number;++$k)
{
$fact = $fact*$k;
}
echo “Factorial of $number is “.$fact;
}
?>

 Find number  whether a  prime or not ?

Answer-
<?php
if(isset($_POST[‘submit’]))
{
$check=0;
$num=$_POST[‘num’];
for($i=2;$i<=($num/2);$i++)
{
if($num%$i==0)
{
$check++;
if($check==1)
{
break ;
}
}
}
if($check==0)
{
echo “It is a Prime Number”;
}
else
{
echo “It is not a Prime Number”;
}
}
?>

 

 Find  number whether  armstrong or not ?

Answer- An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to  number .

For example, 371 is an Armstrong number since 3**3 + 7**3 + 1**3 = 371.
<?php
if(isset($_POST[‘submit’]))
{
$number = $_POST[‘num’]; // get the number entered by user
$temp = $number;
$sum = 0;
while($temp != 0 )
{
$remainder = $temp % 10; //find reminder
$sum = $sum + ( $remainder * $remainder * $remainder );
$temp = $temp / 10;
}
if( $number == $sum )
{
echo “$number is an Armstrong Number”;
}else
{
echo “$number is not an Armstrong Number”;
}
}
?>

 Find year whether  leap year or not ?

Answer-
<?php
if(isset($_POST[‘submit’]))
{
$year=$_POST[‘year’];
if($year%4==0)
{
echo “It is a leap year”;
}
else
{
echo “It is not a leap year”;
}
}
?>

Write a program for this following output ?

1
22
333
4444
55555

Answer-
<html>
<head>
<title>Number Pyramid</title>
</head>
<body>
<?php
$r;
$c;
for($r=1;$r<=5;$r++)
{
for($c=1;$c<=$r;$c++)
{
print(“$r”);
}
print “<br>”;
}
?>
</body>
</html>

 Print a  given number reverse ?

Answer –
<?php
if(isset($_POST[‘submit’]))
{
$rev=0;
$num=$_POST[‘num’];

while($num>=1)
{
$re=$num%10;
$rev=$rev*10+$re;
$num=$num/10;
}
echo “Reverse number of is ” .$rev;
}
?>

Swap two given  values without helping from third variable ?

Answer –
<?php
if(isset($_POST[‘submit’]))
{
$value1=$_POST[‘num1’];
$value2=$_POST[‘num2’];

$value1=$value1+$value2;
$value2=$value1-$value2;
$value1=$value1-$value2;
echo “Value of first variable after swapping” .$value1.”<br />”;
echo “Value of second variable after swapping” .$value2;
}
?>

 

 

We are committed for perfection that is  what outsource2global is known in the world.  if you are looking for outsourcing to india for services like a custom software development  with creative designs or seo digital marketing, Then send us your requirements.

 

Keywords – php interview question and answer, question and answer in php for  fresher and experianced, php logical question and answer

 

 

Summary

 

Reviewer
John

 

Review Date
Reviewed Item
Excellent!! Top 10 PHP Programming/ Logical Interview questions and answers for fresher and experienced to help for getting job.
Author Rating
51star1star1star1star1star

Leave a Reply

Your email address will not be published. Required fields are marked *