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

Revision Answer 2-1

This document contains 10 revision questions about PHP concepts like variables, operators, loops, functions, and forms. Each question provides an explanation or code example as the answer. Some key points covered include defining variables with the $ sign, the different types of operators in PHP, using a for loop to print numbers, defining functions with examples of predefined and user-defined functions, using the return statement in functions, validating forms, and using required fields. A do-while loop example and a function to calculate the area of a square are also provided.

Uploaded by

anshag631
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)
22 views

Revision Answer 2-1

This document contains 10 revision questions about PHP concepts like variables, operators, loops, functions, and forms. Each question provides an explanation or code example as the answer. Some key points covered include defining variables with the $ sign, the different types of operators in PHP, using a for loop to print numbers, defining functions with examples of predefined and user-defined functions, using the return statement in functions, validating forms, and using required fields. A do-while loop example and a function to calculate the area of a square are also provided.

Uploaded by

anshag631
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

Revision Questions

1. What is a variable? How it is defined.


Ans:- A variable is a storage area used to store values that may be integers or
string.
It is defined by using the dollar sign ($) followed by the name of variable.
For example:
$name = “Felix”;
2. What are the different types of operators in PHP?
Ans:- The different types of operators in PHP are:- Arthimetic operators,
Assignment operators, comparison operators, Increment/Decrement operators,
Logical operators and String operators.

3. Write a program using For Loop to print numbers from 10 to 20


<?php
for($i=10; $i<=20; $i++)
{
print “$i”;
printn “<br>”;
}
?>
4. Define a function and write its syntax with an example.
Ans:- A function is a subprogram designed to perform a specific task and return a
value. There are two types of function predefined function and user defined
function.
Syntax:
function functionName()
{
code for execution;
}
Example:
<?php
function sendMsg()
{
print “I have reached ”;
}
sendMsg();
?>
5. How useful is the function with return value? Explain with an example
Ans:- When the return statement is used, a function can return a value once the
function has been executed. The return statement will stop the execution of the
function. Then the return statement sends the value to there where function has
been called.
Example:- There is a program to calculate the area of a square
<?php
Function areaSquare($length,$breadth)
{
$area = $length * $breadth;
return $area;
}
$area = areaSquare(45,45);
print “Area of a square is $area”; ?>
6. List the points to be considered when using POST method,
Ans:- The points to be consider when using the POST method are:-
1. There is no restriction on the data size.
2. Information security can be ensured by sending data through secure HTTP.
7. Why do you need to validate a form?
Ans:- The form thus created contains a number of inputs like text fields, radio
buttons, check boxes etc. The inputs thus received will have to be validated to
ensure that the user has entered relevant values.
8. When should you use Form Required?
Ans:- While an applicant is filling out the admission form, he/she skip some of the
fields. To ensure that all the required fields in by the applicant, the form has to be
validated. This validation is ensured by Form required. At that time, we have to use
Form Required.

9. Explain do while loop with an example.


Ans: The do-while loop executes the statements first and then tests the condition. If
the condition is true, the subsequent iterations is executed. If false, the loop is
terminated.
Syntax,
do
{
Statement(s) to be executed;
}
while(condition);
Example:
<?php
$z=1;
do
{
print “Number is $z”;
$z = $z +1;
} while($z<=5);
?>
10.Write a program using function to find out the area of square using the
parameters passed by the calling function.

Ans:- <?php

function areaSquare($length,$breadth)

$ans=$length*$breadth;

print “The area of square is $ans”;

areaSquare(10,10);

?>

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy