Professional Documents
Culture Documents
Revision Answer1 1
Revision Answer1 1
Ans:-
<?php
$num = 11;
if($num=>10)
{
print “Number is greater number than 10”;
}
elseif($num=>12)
{
print “Number is greater than 12 ” ;
}
else
{
print “It is smaller number than 10 and 12” ;
}
?>
b. Define numeric array and associative array with example.
Ans:- In Numeric arrays each item has an index number. The first item has
index 0, the second item has index 1, etc. To access the item you have to use
the index number inside the square brackets [ ].
For example:
<?php
$cars = arrays (“Volvo”, ”BMW”, ”Toyota ”) ;
print $cars [0];
?>
Associative arrays are arrays that use key and value. It store value inside a key.
Different values can be stored inside a key.
For example:
<?php
$car = array(“brand”=>”Ford”,”model”=>”Mustang”,”year”=>”1964”);
print $car[“brand”];
?>
Ans:- In PHP, both `include` and `require` are used to include the content of another
PHP file within the current PHP script.
d. Why GET and POST method are used in form and write their differences?
Ans: The GET method is used to submit the HTML form data. The
information sent from an HTML form using the GET method is visible to
everyone in the browser's address bar. Therefore, the get method is not
secured to send sensitive information.
POST method is also used to submit the HTML form data. But the data
submitted by this method is collected by the predefined superglobal array
$_POST.The information sent from an HTML form using the POST method is
not visible to anyone.The data sent using POST method is secured.
e. Explain Superglobals array and list out some of the name of superglobal
array?
Ans :Superglobals array are special array which can you access from any part of
the code and you can access them from inside the function or outside of the
function. The some of the name of superglobal array are: $GLOBALS,
$_SERVER, $_REQUEST, $_POST, $_GET etc.
Ans:- A while loop is a control flow statement that allows you to execute a block
of code repeatedly as long as a specified condition evaluates to true.
<?php
$num = 12;
while($num=>26)
$num = $num + 2;
?>
Programs
Ans:- <?php
$num = 12;
while($num=<26)
$num = $num + 2;
?>
Ans:- <?php
$num = 11;
while($num=<23)
$num = $num + 2;
?>
c. Write a program using function to find out the area of rectangle using the
parameters passed by the calling function.
Ans:- <?php
function areaRect($length,$breadth)
$ans=$length*$breadth;
areaRect(10,20);
?>
Ans:-
<html>
<body>
<p><input type="submit"></p>
</form>
<?php
if($_SERVER["REQUEST_METHOD"]=="POST")
$email = check_input($_POST["email"]);
function check_input($data)
$data = trim($data);
$data = stripslashes($data);
return $data;
?>
</body>
</html>
e. Write down the syntax for while loop and for loop.
Ans:- <?php
while(condition)
{
code to be executed;
}
?>
<?php
for(intialisation;condition;increment/decrementOperator)
{
code to be executed;
}
?>
Output:
Mustang.
Note:- since in associative array value is stored in key and to access the key
we have to write key in big bracket with double inverted comma so model is
key and its value is Mustang.
ii. <?php
$student = array("Alex","Emma","Thomas","Marie");
print $student[0];
print "<br>";
print $student[1];
?>
Output
Alex
Emma
Note:- This is numeric array. In numeric array we store value in index. So Alex is
stored in 0 index, Emma in 1 index, Thomas in 2 index and Marie in 3 index. To
access the value Alex stored in 0 index we have to write the 0 index in big bracket.
But in numeric array we don’t write double inverted comma.