La fonction Moyenne() en langage PHP :
Exemple :
<?php
function moyenne($x,$y){
$moy=($x+$y)/2;
return $moy;
}
echo "La moyenne de x , y est :".moyenne(2,4);
?>
Le navigateur affiche ce résultat :
Les fonctions avancées :
Le code PHP associer à ce résultat est :
<body>
<?php
function moyenne($x,$y){
$som=($x+$y);
$moy=$som/2;
$res=array($som,$moy);
return $res;
}
$table1=moyenne(2,4);
$table2=moyenne(4,4);
?>
<table border="1" style="text-align:center">
<tr>
<td>La somme </td>
<td>la moyenne </td>
</tr>
<tr>
<td><?php echo $table1[0];?> </td>
<td><?php echo $table1[1];?> </td>
</tr>
<tr>
<td><?php echo $table2[0];?> </td>
<td><?php echo $table2[1];?> </td>
</tr>
</table>
</body>
0 commentaires:
Enregistrer un commentaire