Inicio PHP
This commit is contained in:
49
Practicas/Practicas_PHP/codigo/INTRO2_PHP_BUCLES.php
Executable file
49
Practicas/Practicas_PHP/codigo/INTRO2_PHP_BUCLES.php
Executable file
@@ -0,0 +1,49 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Intro2 PHP</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Bucles</h1>
|
||||
<?php
|
||||
// foreach
|
||||
$animalesFantasticos = ['fénix', 'dragón', 'grifo', 'pegaso', 'cerbero'];
|
||||
foreach ($animalesFantasticos as $animal) {
|
||||
echo $animal . ' ';
|
||||
}
|
||||
echo '<br>';
|
||||
//si necesitamos la key
|
||||
foreach ($animalesFantasticos as $posicion => $animal) {
|
||||
echo "El animal $animal ocupa la posición $posicion";
|
||||
echo '<br>';
|
||||
}
|
||||
//range crea un array entre un rango especificado
|
||||
//range($inicio, $fin, $pasos);//Esquema
|
||||
foreach (range(1, 5) as $num) {echo $num;};
|
||||
|
||||
//for
|
||||
//Estructura for (variable inicio; condicional; incremento) {...}
|
||||
echo '<br>';
|
||||
for ($i = 0; $i < 10; $i++) {
|
||||
echo $i;
|
||||
}
|
||||
echo '<br>';
|
||||
//while
|
||||
// Estructura while (condicional) {...}
|
||||
$i = 1;
|
||||
while ($i < 12) {
|
||||
echo $i++;
|
||||
}
|
||||
echo '<br>';
|
||||
//do-while
|
||||
// Estructura do {...} while (condicional) una vez siempre
|
||||
$i = 1;
|
||||
do {
|
||||
echo $i++;
|
||||
} while ($i < 10);
|
||||
echo '<br>';
|
||||
?>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user