Nesta aula desenvolveremos um Script que retorna a tabuada que foi solicitada pelo usuário. Entenderemos também, a razão pela qual optamos pela estrutura de repetição for na implementação deste código. |
EXEMPLO FEITO EM AULA
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<title>Tabuada - Curso PHP - eXcript</title>
</head>
<body>
<?php
$tab = 0;
if(isset($_POST["edTABUADA"])){
$tab = $_POST["edTABUADA"];
if(!is_numeric($tab)){
echo "<br>O valor informado não é um número.<br>";
}else{
// for($num=0; $num<=10; $num++){
// echo $num . " x " . $tab . " = " . ($num * $tab) . "<br>";
// }
//$num x $tab = ($num * $tab)
//0 x 5 = 0
//1 x 5 = 5
$num=0;
while($num<=10){
echo $num . " x " . $tab . " = " . ($num * $tab) . "<br>";
$num++;
}
}
}
?>
<form method="post">
<input type="text" name="edTABUADA" >
<input type="submit">
</form>
</body>
</html>
Tags curso, php
Comentários
comments powered by Disqus