Esempio n. 1
0
<!DOCTYPE html>
<html lang="">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title></title>
    <link rel="stylesheet" type="text/css" href=" ">
    </head>
    <body>
      <!-- función simple -->
      <?php 
function crearlista($elementos)
{
    echo "<ul>";
    for ($i = 0; $i < $elementos; $i++) {
        echo "<li>{$i}</li>";
    }
    echo "</ul>";
}
crearlista(5);
?>
    </body>
</html>
<!DOCTYPE html>
<html lang="">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title></title>
    <link rel="stylesheet" type="text/css" href=" ">
    </head>
    <body>
      <?php 
function crearlista($v)
{
    echo "<ul>";
    foreach ($v as $valor) {
        echo " <li>{$valor}</li>";
    }
    echo "</ul>";
}
$data = array(1, 2, 3, 4, 5, 6);
$data2 = array('A' => 1, 'B' => 2);
crearlista($data2);
?>
    </body>
</html>
Esempio n. 3
0
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
  </head>
  <body>
    <?php 
function crearlista($vector)
{
    echo "<ul>";
    foreach ($vector as $value) {
        echo "<li>{$value}</li>";
    }
    echo "</ul>";
}
$array = ["Jesus", "Pepe", "Manuel", "Manuela"];
crearlista($array);
?>
  </body>
</html>