Use of Variables in PHP

Use of Variables in PHP

Instructor-svgAl-Mamun Sarkar
Apr 22 , 2020

The following code shows how to use local variables as well as global variables in php in PHP Programming.

Variable:

$txt = "Artofcse";
$x = 10;
$y = 15.5;

echo "I love $txt!";
echo "<br/>";
echo "I love " . $txt . "!";

echo "<br/>";
echo $x + $y;

Output:

I love Artofcse!
I love Artofcse!
25.5

 

Global Variable:

$a = 50;
$b = 100;

function myTest() {
    global $a, $b;
    $b = $a + $b;
}

myTest();
echo $b;

Output:

150

 

  • Share On:
  • fb
  • twitter
  • pinterest
  • instagram