# Variable Scope

- Thread: https://externals.io/message/4262
- Original archive: https://news-web.php.net/php.internals/4262
- Started by LingWitt@insightbb.com on 2003-08-30T14:18:00+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #4262 — LingWitt@insightbb.com — 2003-08-30T14:18:00+00:00

URL: https://externals.io/message/4262#4262

Variable scope is mediocre at best. For instances:

$array = array(1, 2, 3, 4, 5);

for ($i = 0; $i < 5; $i++)
{
	$num = $array[$i];
	echo $num;
	for ($i = 0; $i < 5; $i++)
	{
		echo $num * $i;
	}
}

The inner loop $i doesn't mask the outer loop $i.
Thus, the whole things gets screwed up.

---

## #4264 — Derick Rethans — 2003-08-30T14:21:57+00:00

URL: https://externals.io/message/4262#4264 · In reply to: #4262

> The inner loop $i doesn't mask the outer loop $i.
> Thus, the whole things gets screwed up.

? This example works perfectly fine. What's your problem here? What do 
you mean with "mask the outer loop"? Of course if you modify $i INSIDE 
the loop the outer one is affected.

Derick

-- 
"Interpreting what the GPL actually means is a job best left to those
                    that read the future by examining animal entrails."
-------------------------------------------------------------------------
 Derick Rethans                                 http://derickrethans.nl/ 
 International PHP Magazine                          http://php-mag.net/
