0% found this document useful (0 votes)
19 views7 pages

PHP Code Output and Functionality Guide

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views7 pages

PHP Code Output and Functionality Guide

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

SNO QUESTION

1 The output of the following code is


$a=5;
echo ++$a;
2 The output of the following code is
$M=5;
echo $M++;
3 The output of the following code is
$a=5; $b=2;
$a=$b;
echo $a,$b;
4 The output of the following code is
$x=5;
$x+=10;
echo $x;
5 The output of the following code is
$x=15;
$y=$x%3;
echo $y;
6 Write Output.
$x=5;
$y=10;
$y+=$x;
echo"Remainder after addition assignment=";
echo $y%6;
7 Write the output.
<?php
$a=10;
$a*=3;
$b=10;
$b%=2;
print"a*=3 is".$a;
echo"<br>";
print"b%=2 is ".$b;
?>
8 Write the output
<?php
$a=1;
$a++;
$b=$a++;
print"a=".$a;
echo"<br>";
print"b= ".$b;
?>
9 Write the output of the following program.
<? php
$a=5; b=10;
$c=($a+$b)*$a;
echo $c;
?>
10 Write the output of the following php script.
<?php
$a=25;
$b=5;
$c=$b++;
$d=++$b;
$e=$d%$c;
print "b=$b";
echo "<br>";
print "b= ".$b;
echo "<br>";
print "c=\$c";
echo "<br>";
print "c= ".$c;
echo "<br>";
echo ($a);
?>
11 Write PHP code embedded in HTML file to do the
following
i. Set values 20 and 10 to variables $x and $y
respectively.
ii. Increment $x by 1 value using increment operator.
iii. Decrement $y value by 1 using decrement operator.
iv. Find remainder using modulo operator when $x÷$y
and store in $r.
v. Display the values of $x, $y and $r.

12 What will be the output of the following


$emp=array
(
array(“Enoc”,10,90),
array(“Kevin”,60,50),
array(“Nalini”,13,19)
);
echo $emp[1][1];
13 What will be the output of the following PHP code
<?php
function prd($x, $y) {
$z = $x * $y;
echo $z;
}
echo “product =“;
prd(5, 10);
?>
14 Write PHP statement to store the values 4,5,6 and 7 in
the indexed array with name $data.
15 Write the output of the following PHP script.
<?php
$x=array(10,20,30);
$y=array(50,60,80);
$z=$y[1]+$x[2];
echo“sum=”;
echo $z;
?>
16. Write the output of the following PHP code.
<?php
$s=[11,33,77];
foreach($s as $v)
echo $v,”<br>”;
?>
17 What will be the output of the following in PHP code?
<?php
$array = array(“a”=>10, “b”=>20, “c”=>30);
foreach($array as $key =>$value) {
echo $key.”=>”.$value.”<br>”;
}
?>
18. Write the output of the following PHP script.
<?php
$x=array(10,20,30);
$y=array(50,60,80);
$z=$y[1]+$x[2];
print(“sum=”.$z.” Rupees”);
?>
19 Write the output of the following PHP code.
<?php
//…….function definition ………..
function sum($rowno)
{
//……array…………..
$arr = array(
array(1,2,3),
array(4,5,6),
array(7,8,9)
);
//……………………..
$s = $arr[$rowno][0] + $arr[$rowno][1] +$arr[$rowno][2];
echo “Row=”, $rowno;
echo “ sum=”,$s;
echo “<br>”;
}
//……function calls…….
echo sum(0);
echo sum(1);
echo sum(2);
?>
20. Write the output.
if (4<4.0)
echo “Hello”;
else
echo “Hi”;
21 Write the output.
<?php
$x = 0;
if ($x++ ==0)
echo “hi”;
else
echo “how are u”;
?>
22 Write the output.
<?php
$x = 0;
if (++$x ==0)
echo “hi”;
else
echo “how are u”;
?>
23 Write the output.
<?php
$x = 10;
if (($x>0)&&($x<20))
echo “hi”;
else
echo “how are u”;
?>
24. Write the output.
<?php
$pmark = 35;
$smark=70;
if ($smark>=$pmark)
echo “Eligible”;
else
echo “Not eligible”;
?>
25. Write the output.
<?php
$x = 1;
switch($x)
{
case 2:
echo “Twice”;
break;
case 1:
echo “Once”;
break;
}
echo “ done”;
?>
26. Write the output.
<?php
$x = 55;
if ($x>90)
echo “Awesome”;
else if ($x>60)
echo “Excellent”;
else
echo “Good”;
?>
27. Write PHP if statement to check whether the given
number(n) is even or odd.

28. Write PHP if…elseif…else statement to print


whether the given number n is positive, negative
or zero.

29. Write PHP code to do the following.


i) if given number is divisible by 3 then print
“DIVISIBLE BY 3”
ii) otherwise check whether the number is even.
- if even print “EVEN”
- otherwise print “NOT EVEN”

30. Write the output of the following program.


<?php
$Pass_Mark=35;
$Student_Mark=70;
if ($Student_Mark>= $Pass_Mark)
{
echo “The Student is eligible for promotion”;
}
else
{
echo “The Student is not eligible for promotion”;
}?>
31. What is the output of the following code?
$array=array(1,2,3,4,5);
foreach ($array as $value)
{
echo $value;
}
32 What is the output of the following code snippet?
$i=1;
while($i<=5)
{
echo $i.”<br>”;
$i++;
}
32 Write a PHP code to print 1 to 10 numbers in
ascending order using for loop.

33 What will be the output of the following PHP


code?
$k=1;
while ($k>4) { print k;}
print “ITS ALL OVER”;
34 What will be the output of the following PHP
code?
$m=0;
$k=array(4,5,6);
foreach($k as $x) {
$m+=$x; }
print $m;
35 What will be the output of the following PHP
code?
$k=array(“Let us”, “ be”, “ happy”);
foreach($k as $x) {
echo $x; }
36 What will be the output of the following PHP
code?
$m=0;
$k=array(4,5,6);
foreach($k as $x) {
echo $x%2; }
37 Write the output of the following PHP code.
$k=array(40,45,50,55,60);
foreach($k as $x) {
if ($x==60)
print $x; }
38 What is the output of the following code?
for($i=5;$i>=1;$i--)
{
echo $i;
}
39 Write PHP code to print first 50 natural numbers.

40 Write the output of the following PHP code.


$s=array(11,42,30);
foreach($s as $v)
print $v;
41 Write the output of the following PHP code.
$i=10;
while($i<17)
{
echo “PHP- while”.”<br>”;
$i+=2;
}
42 Given the following code, answer the questions
given
for($i=1; $i<3; $i++)
{
echo $i;
echo “<br>”;
}
a) How many times the code block will executed.
b) Write the initialization, condition and increment
parts of the ‘for loop’.
c) Write the output of the code.

43 Write PHP program to do the following.


• Store numbers 1 to 10 in array $a.
• Iterate the array $a using foreach loop to print only
the odd numbers.

44 Write PHP code to connect to MySQL with the


following details.
server name: localhost
user name: root
password: mysqlroot
database name: mydatabase

You might also like