1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Array Scope in PHP

Discussion in 'PHP' started by Kalyse, Apr 19, 2007.

  1. #1
    I have an array called $configuration its got around 50 of my sites configurations in.

    I need to access these from functions.

    I am using

    global $configuration

    But thats not working. How can I make all my $configuration array accessible accross every function I want.
     
    Kalyse, Apr 19, 2007 IP
  2. decepti0n

    decepti0n Peon

    Messages:
    519
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #2
    How is it not working? Using global $configuration should allow its use inside a function

    That or just pile them into sessions, I sometimes use the session array for things i need in and out of functions
     
    decepti0n, Apr 19, 2007 IP
  3. wmtips

    wmtips Well-Known Member

    Messages:
    601
    Likes Received:
    70
    Best Answers:
    1
    Trophy Points:
    150
    #3
    If you have $configuration definition outside the function, the global keyword should work. If you need to publish variable as global inside the function, you can use the construction like this:
    
    $GLOBALS['configuration'] = array('your','array','members');
    
    PHP:
     
    wmtips, Apr 19, 2007 IP
  4. Kalyse

    Kalyse Peon

    Messages:
    1,221
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I managed to get it working, I dont know what was wrong, but what I thought I was doing was right but wasnt working. Moved some things and it worked.

    Glad to know its all okay
     
    Kalyse, Apr 19, 2007 IP