image


Valora:  2.5/5
Inicio » PHP » PHP Tutorial » Functions and libraries




Functions

The use of functions enables us to group several statements under only one name and to call them several times from different places, saving us the need to rewrite them.

<?php
   function Nombre(param1, param2...)
   {
      statement1;
      statement2;
      statement3;
      statement4;

      return return_value;
   }
?>

We can optionally pass parameters to the functions to be known as local variable, and we can also return a result with the "return value" statement. This produces the ending of the function returning a value.


<!-- PHP Tutorial WebEstilo.com -->
<html>
<head>
   <title>PHP Example</title>
</head>
<body>
<?php
   
   function media_aritmetica($a, $b)
   {
      $media=($a+$b)/2;
      return $media;
   }
   
   echo media_aritmetica(4,6),"<br>";
   echo media_aritmetica(3242,524543),"<br>";
   
?>

</body>
</html>

Execute View code






WebEstilo.com - Introduzca su e-mail y conozca las novedades. No hacemos Spam.
Google
  Web WebEstilo.com   
 
Valid HTML 4.01!
Última modificación:24 de Diciembre de 2004. Spain - España.
© 1998-2004 por Joaquin Gracia. Todos los derechos reservados.