---
title: "Global and Local Scope"  
description: "Global and Local Scope"  
author: "Anonymous User"  
published: 2018-07-19  
updated: 2018-07-19  
canonical: https://www.mindstick.com/forum/34625/global-and-local-scope  
category: "php"  
tags: ["web development", "php", "variable"]  
reading_time: 1 minute  

---

# Global and Local Scope

[Difference](https://www.mindstick.com/articles/157114/good-news-or-bad-news-and-the-difference-is) between [Global and Local](https://www.mindstick.com/forum/159120/explain-the-concept-of-scope-in-javascript-and-the-differences-between-global-and-local-scope) [Scope](https://www.mindstick.com/interview/372/what-are-the-different-scopes-for-java-variables) [variables](https://www.mindstick.com/articles/715/php-variables) in [PHP](https://www.mindstick.com/articles/12149/php-constant-and-php-variables) ?

## Replies

### Reply by Prakash nidhi Verma

[Global](https://www.mindstick.com/articles/13127/macro-and-microeconomics-concepts-in-relation-to-global-organization-management) Scope:

Global scope is a variable which declared outside a function and can only be accessed outside a function.

Example :

```
<?php
$x = 5; // global scope
function mindstick() {
    echo "<p>Variable x inside function is: $x</p>";
}
mindstick();
echo "<p>Variable x outside function is: $x</p>";
?>
```

\

[Local](https://www.mindstick.com/forum/546/how-to-create-local-user-in-windows-8) Scope:

A variable declared within a function has a LOCAL SCOPE and can only be accessed within that function.

Example :

```
<?php
function mindstick() {
    $x = 5; // local scope
    echo "<p>Variable x inside function is: $x</p>";
}
mindstick();
echo "<p>Variable x outside function is: $x</p>";
?>
```


---

Original Source: https://www.mindstick.com/forum/34625/global-and-local-scope

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
