Need Assistance?

support@tutorialshub.in

Variables, Data Types & Operators

Variables & Variable Scope (global, static)

ADVERTISEMENT
PHP Free Lesson
5 min read
ADVERTISEMENT

In PHP, every variable starts with a dollar sign ($), followed by a letter or underscore (e.g., $userName, $_count). Variable names are case-sensitive ($age and $Age are different).

Understanding Scope

  • Local Scope: Variables created inside a function only exist inside that function.
  • Global Scope: Variables outside functions aren't automatically visible inside functions—you must pass them as parameters (recommended) or use global $var;.
  • Static Variables: Declared with static $count = 0; inside a function so the value is remembered between function calls.
ADVERTISEMENT
Hi, I'm Tuby! Here to help you