-3

I want to get a value of variable stored in another php scope

<?php
    $count=3;
?>

<?php
    echo($count); //does not print the value
?>

The 2 php scopes are in the same page.

Jason
  • 15,017
  • 23
  • 85
  • 116
israa
  • 95
  • 1
  • 1
  • 5

2 Answers2

2
In your case , it MUST show 3

Check this: http://php.net/manual/en/language.variables.scope.php

Sudhir Bastakoti
  • 99,167
  • 15
  • 158
  • 162
0

This link is full of examples like the one you have listed here.

http://php.net/manual/en/language.variables.scope.php

try using var_dump($varname)

you dont need to put the parenthesis (around the var)

<?php
$count=3;

echo $count; //will work

var_dump($count) //when in doubt, look at what is in the variable

?>
jamesTheProgrammer
  • 1,747
  • 4
  • 22
  • 34