-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path010-switch.php
More file actions
129 lines (114 loc) · 3.6 KB
/
010-switch.php
File metadata and controls
129 lines (114 loc) · 3.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<h2>SWITCH</h2>
<?php
$lugarNaciemiento="Madrid";
switch ($lugarNaciemiento){
case "barcelona":
$mnsg= "Eres Catalán";
break;
case "zaragoza":
$mnsg="Eres Maño";
break;
default:
$mnsg="Eres ciudadano del mundo";
}
echo $mnsg;
?>
<!------------------------------------------------------------------------->
<h2>Validación con switch múltiple</h2>
<?php
$lugarNacimiento="huesca";
if($lugarNacimiento=="huesca"||$lugarNacimiento=="teruel"||$lugarNacimiento=="zaragoza"){
$msg="Eres Maño";
}else if($lugarNacimiento=="barcelona"){
$msg="Eres Catalán";
}else{
$msg="Eres ciudadano del mundo";
}
echo $msg;
?>
<!------------------------------------------------------------------------->
<h2>Ejercicio</h2>
<?php
$edad=1900;
$destino="francia";
if(2015-$edad>=18){
switch (mb_strtolower($destino,"UTF-8")){
case "francia":
$msg= "Von voayage";
break;
case "alemania":
$msg="gute fahrt";
break;
case "inglaterra":
$msg="Good Trip";
break;
default:
$msg="Buen viaje";
}
}else{
$msg="Debes viajar en compañia de un adulto";
}
echo $msg;
?>
<!------------------------------------------------------------------------->
<h2>Práctica validación de hora</h2>
<form action="<?php echo $_SERVER["PHP_SELF"] ?>" method="get">
<input name="hora" type="number" placeholder="Hora 0-23" required>*
<input name="formHora" type="submit" value="Send">
</form>
<?php
if(isset($_GET["formHora"])){
extract($_GET);
if(0<=$hora && $hora<=23){
switch($hora){
case 6:
case 7:
case 8:
case 9:
case 10:
case 11:
$msgh= "Buenos días";
break;
case 12:
case 13:
case 14:
case 15:
case 16:
case 17:
case 18:
case 19:
case 20:
$msgh= "Buenas tardes";
break;
default :
$msgh= "Buenas noches";
}
}else{
$msgh= 'Hora no válida';
}
echo $msgh;
}
?>
<!-------------------------------------------------------------------------------->
<h2>Recorrer un array tradicional</h2>
<?php
$a=0;
$alumnos=array("oscar","jairo","jesús","imanol");
while ($a<count($alumnos)){
echo $alumnos[$a++].', ';
}
?>
</body>
</html>