PHP programms

Function-1
<html>
<body>
<?php
function mySum($numX, $numY){
    $total = $numX + $numY;
    return $total;
}
$myNumber = 0;
echo "Before the function, myNumber = " .$myNumber. "<br />";
$myNumber = mySum(3, 4); // Store the result of mySum in $myNumber
echo "After the function, myNumber =  ".$myNumber. "<br />";
?>
</body>
</html>
Function-2
<html>
<body>
<?php

$makefoo = true;
bar();
if ($makefoo) {
  function foo()
  {
    echo "I don't exist until program execution reaches me.\n";
  }
}
if ($makefoo) foo();
function bar()
{
  echo "I exist immediately upon program start.\n";
}
?>
</body>
Function-3

<html>
<body>
<?php
function foo()
{
  function bar()
  {
    echo "I don't exist until foo() is called.\n";
  }
}
foo();

?>
</body>
</html>
Function-4
<html>
<body>
<?php

function A(){
    echo("Hello, I'm A\n");

}
echo("I just defined A\n");
return;

function B(){
    echo("Hello, I'm B\n");

}
echo("I just defined B\n");
?>
</body>
</html>
Function-5
<html>
<body>
<?php
function a($n){
  b($n);
  return ($n * $n);
}

function b(&$n){
  $n++;
}
echo a(5);
?>
</body>
</html>
Function-6

<html>
<body>
<?PHP
/* Define Function */
function plus($a, $b){
$c=$a+$b;
echo "$a+$b=$c </br>";
}
plus(2,5);
?>
</body>
</html>
Function-7

<html>
<body>
<?php
class A {
        function A() { }

        function ech() {
                $a = func_get_args();
                for( $t=0;$t<count($a); $t++ ) {
                        echo $a[$t];
                }
        }
}      
$test = new A();
$test->ech(0,1,2,3,4,5,6,7,8,9);
?>
</body>
</html>
Function-8

<html>
<body>
<?php

// Test of static/non-static method overloading, sort of, for php
class test {
    var $Id = 2;
    function priint ($id = 0) {
        if ($id == 0) {
            echo $this->Id;
            return;
        }
        echo $id;
        return;
    }
}
$tc = new test ();
$tc->priint ();
echo "\n";

Function-9

<html>
<body>
<?php
function small_numbers()
{
    return array (0, 1, 2);
}
list($zero, $one, $two) = small_numbers();
?>
</body>
</html>

Inheritance 

<html>
<body>
<?php
class p {
   
    function p() {
        print "Parent's constructor\n";
    }
   
    function p_test() {
        print "p_test()\n";
        $this->c_test();
    }
}

class c extends p {
   
    function c() {
        print "Child's constructor\n";
        parent::p();
    }
   
    function c_test() {
        print "c_test()\n";
    }
}

$obj = new c;
$obj->p_test();

?>
</body>
</html>
Recursion

<html>
<body>
<?php
function recursion($a)
{
    if ($a < 10) {
        echo "before: ".$a."\n";
        recursion($a + 1);
        echo "after: ".$a."\n";
    }
}
recursion(0);
?>
</body>
</html>