0% found this document useful (0 votes)
82 views

Top Important Ca Program Question 2024

The document provides 17 PHP code snippets with explanations and outputs. It covers topics like conditional statements, loops, functions, arrays and foreach loops. Each code snippet is presented with the code, an explanation and the expected output.
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)
82 views

Top Important Ca Program Question 2024

The document provides 17 PHP code snippets with explanations and outputs. It covers topics like conditional statements, loops, functions, arrays and foreach loops. Each code snippet is presented with the code, an explanation and the expected output.
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
You are on page 1/ 5

J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

TOP IMPORTANT PROGRAM QUESTION


XII – COMPUTER APPLICATIONS
1.What will be the output of the following PHP code?
<?php
$x = 10;
if ($x > 5)
{
echo “x is greater than 5”;
} ?>

Output:
x is greater than 5

2.What will be the output of the following PHP code?


<?php
$x = 10;
if ($x > 5)
{
echo “x is greater than 5”;
}
else
{
echo “x is not greater than 5”;
}
?>

Output:
x is greater than 5

3.What will be the output of the following PHP code?


<?
php
$x = 12; if
($x > 20)
{
echo “x is greater than 20”;
}
else
if ($x > 15)
{
echo “x is greater than 15 but not greater than 20”;
}
elseif ($x > 10)
{
echo “x is greater than 10 but not greater than 15”;
}
else
https://csknowledgeopener.com 1 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.
{
echo “x is not greater than 10”;
}
?>
Output:
x is greater than 10 but not greater than 15

4. To print the numbers from 1 to 5 in ascending order


for ($i = 1; $i<= 5; $i++)
{
echo $i . “<br>”;
}
Output:
1
2
3
4
5

5. To print the numbers from 5 to 1 in descending order


for ($i = 5; $i>= 1; $i --)
{
echo $i . “<br>”;
}
Output:
5
4
3
2
1

6. To print the numbers from 1 to 5


$i = 1;
while ($i<= 5)
{
echo $i . “<br>”;
$i++;
}
Output:
1
2
3
4
5

7. To print the numbers from 1 to 5


$i = 1;
do
{
https://csknowledgeopener.com 2 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.
echo $i . “<br>”;
$i++;
}
while ($i<= 5);
Output:
1
2
3
4
5
8. To print the elements of an array:
$array = array(1, 2, 3, 4, 5);
foreach ($array as $value)
{
echo $value . “<br>”;
}
Output:
1
2
3
4
5

9. What is the output of the following code?


$array = array(1, 2, 3, 4, 5);
foreach ($array as $value)
{
echo $value;
}
Output:
12345

10. What is the output of the following code snippet?


$i = 1;
while ($i <= 5)
{
echo $i . “<br>”;
$i++;
}
Output:
1
2
3
4
5
11. Write a PHP code to print 1 to 10 numbers in ascending order using for loop.
<?php
for ($i = 1; $i<= 10; $i++)

https://csknowledgeopener.com 3 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.
{
echo $i . "<br>";
}
?>

Output:
1
2
3
4
5
6
7
8
9
10

12. What is the output of the following code snippet?


<?php
function printGreeting()
{
echo “Hello, world!”;
}
printGreeting();
?>
Output:
Hello, world!

13. What is the output of the following code snippet?


<?php
function greet($name)
{
echo “Hello, $name!”;
}
greet(“Barath”);
?>
Output:
Hello, Barath!

14. What is the output of the following code snippet?


<?php
function addNumbers($x, $y)
{
echo $x + $y;
}
addNumbers(10,40);
?>
https://csknowledgeopener.com 4 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.
Output:
50

15. What is the output of the following code snippet?


<?php
$ages = array( “Arun” => 25, “Balu” => 30, “Naveen” => 28 );
echo $ages[“Arun”];
echo $ages[“Balu”];
echo $ages[“Naveen”];
?>
Output:
253028

16. What is the output of the following code snippet?


<?php
$student = array( “name” => “Barath”, “age” => 23, “place”=> “Sirugambur”, “city” => “Trichy”, );
echo $student[“name”];
echo $student[“age”];
?>
Output:
Barath23

17. What is the output of the following code?


$array = array(“a” => 1, “b” => 2, “c” => 3);
foreach ($array as $key => $value)
{
echo $key . “ => “ . $value . “<br>”;
}
Output:
a => 1
b => 2
c => 3

PREPARED BY

J. ILAKKIA M.Sc., B.Ed., M.Phil.


Computer Instructor Grade-I
Govt. Hr. Sec. School
V.Pagandai, Villupuram 605 501.

https://csknowledgeopener.com 5 http://www.youtube.com/c/csknowledgeopener

You might also like