Wrox Programmer Forums
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 4th, 2003, 06:55 PM
Authorized User
 
Join Date: Jul 2003
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default Scope of array

Do array elements have a default scope? I thought they might be global because in one of my functions I could only access them through $GLOBALS['array']['key']. But if they were global, I would expect to be able to access the array elements within the function by simply using $array['key'] - but this didn't work.

So what's the actual scope of an array element?

 
Old November 4th, 2003, 08:10 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

An array element has the same scope as the array variable itself.

If you're in function scope, you need to either use the $GLOBALS superglobal array or the 'global' keyword to import global variables into function scope.

  http://www.php.net/variables.scope


Take care,

Nik
http://www.bigaction.org/





Similar Threads
Thread Thread Starter Forum Replies Last Post
Static Scope JaneDean Beginning PHP 0 November 25th, 2008 02:07 AM
Scope Issue iceman90289 C# 2005 8 April 5th, 2008 03:41 PM
the scope of variable ccj_999 C++ Programming 9 October 26th, 2006 10:35 AM
scope problem jc Javascript 0 July 29th, 2003 09:27 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.