Monday, August 1, 2022

Php functions

 <h3>Odd even programme</h3>
<?php
function user()
{
for ($i=0; $i<=10 ; $i++) 

if ($i%2==0) 
{
echo "even=".$i."<br>";
}
else
{
echo "odd=".$i."<br>";
}
}
}
user();
?>
<h3>With argument with return type</h3>
<?php
  function student($a,$b)
  {
echo "we are in student function <br>";
 echo "a=$a b=$b<br>";
echo "sum of number a+b=($a+$b)<br>";
  $avg=($a+$b)%2;
  return $avg;
  }
  function teacher()
  {
  $a=student(20,40);
echo "<br>we are inside teacher  function<br>";
echo "<br>avg=$a";
  }
    teacher ();
?>
<h3>Without argument with return type:-</h3>
<?php
  function student()
  {
 $a=90;
 $b=80;
 $sum=$a+$b;
 echo "a=$a b=$b<br>";
echo "sum of a+b is=$sum<br>";
  return $sum%2;
  }
  $avg=student();
echo "avg=$avg<br>";
?>

No comments:

Post a Comment