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

$ - GET $CM $ - GET $meter $CM: Isset Floatval

guide for programming in php
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)
3 views

$ - GET $CM $ - GET $meter $CM: Isset Floatval

guide for programming in php
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/ 4

<?

php

// Sequential
if(isset($_GET['convert'])){
$cm = floatval($_GET['centimeter']);

$meter = $cm / 100;

//Conditional
if (isset($_GET['operation'])) {
$num1 = floatval($_GET['num1']);
$num2 = floatval($_GET['num2']);
$operation = $_GET['operation'];

//if-statement
if ($operation == "+"){
$result = $num1 + $num2;

}else if($operation == "-"){


$result = $num1 - $num2;

}else if($operation == "x"){


$result = $num1 * $num2;

}else{
$result = $num1 / $num2;

//switch case
/*switch($operation)
{
case '+':
$result = $num1 + $num2;
break;

case '-':
$result = $num1 - $num2;
break;

case 'x':
$result = $num1 * $num2;
break;

case '/':
$result = $num1 / $num2;
break;

default:
$result = "Error: Invalid operation !!";
break;
}*/

// Looping
$output = "";
if(isset($_GET['generate'])){
$number = floatval($_GET['number']);

//for loop
/*for ($x = 1; $x<= $number; $x++){
$output .= $x . " ";
}*/

//for loop conditional


/*for ($y=1;$y<=$number;$y++){
if ($y%2===0){
$output .= $y . " ";
}
}*/

//while loop
/*$x=1;
while($x<=$number){
$output .= $x . " ";
$x++;
}*/

//while loop conditional


/*$x=1;
while($x<=$number){
if($x%2===0){
$output .= $x . " ";
}
$x++;
}*/

//do while loop


/*$x=1;
do{
$output .= $x . " ";
$x++;
}while($x<=$number);*/

//do while loop conditional


$x=1;
do{
if($x%2===0){
$output .= $x . " ";
}
$x++;
}while($x<=$number);

}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<form action="<?= $_SERVER['PHP_SELF'] ?>" method="get">
<label for="cm">Enter centimeter: </label>
<input type="number" name="centimeter" id="centimeter">
<label for="result">Meter: </label>
<input type="number" name="meter" id="meter" value="<?= $meter ?>"
disabled>
<input type="submit" value="Convert" name="convert"><br>
</form>

<h1>Dynamic Value</h1>
<form action="<?= $_SERVER['PHP_SELF'] ?>" method="get">
<h3>CONDTIONAL STATEMENT (SWITCH CASE / IF -STATEMENT)</h3>
<label for="num1">Enter num1: </label>
<input type="number" name="num1" id="num1"><br><br>
<label for="num2">Enter num2: </label>
<input type="number" name="num2" id="num2"><br><br>
<label for="result">Result: </label>
<input type="number" name="result" id="result" value="<?= $result ?>"
disabled><br><br>

<input type="submit" value="+" name="operation">


<input type="submit" value="-" name="operation">
<input type="submit" value="x" name="operation">
<input type="submit" value="/" name="operation">

</form>

<form action="<?= $_SERVER['PHP_SELF'] ?>" method="get">


<h3>ITERATIVE STATEMENT (FOR LOOP, WHILE LOOP, DO-WHILE LOOP)</h3>
<h4>A.1. FOR LOOP (SEQUENTIAL)</h4>
<label for="number">Enter number: </label>
<input type="number" name="number" id="number">
<input type="submit" value="Generate" name="generate"><br>

<h2 name="output" id="output" value=""><b>For Loop: </b><?= $output


?></h2>

<h4>A.2. FOR LOOP (CONDITIONAL)</h4>


</form>
</body>
</html>

You might also like