Search This Blog

global variable in php

<?php

$num1=10;
$num2=5;

function add()
{
  global $num1,$num2;
  return $num1+$num2;
}

function sub($num1,$num2)
{
  return $num1-$num2;
}

echo 'addition  with out global variables : '. add().'<br>';

echo 'subtraction with global variables : '.sub($num1,$num2);

?>output :

addition with out global variables : 15
subtraction with global variables : 5

Share Links

Related Posts Plugin for WordPress, Blogger...