Re: Variable Scope
| From: | LingWitt at insightbb dot com | Date: | Sat, 30 Aug 2003 14:30:26 +0000 |
| Subject: | Re: Variable Scope | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-4266@lists.php.net to get a copy of this message | ||
Since the inner loop declares $i again, it should mask the outer loop's $i as per other languages. Besides being useful, it makes more sense. Otherwise, the declaratory statement in the second loop is completely meaningless.
On Saturday, Aug 30, 2003, at 10:21 America/New_York, Derick Rethans wrote:
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.
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.