[Solved] Array...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dmakris
Forum Newbie
Posts: 11
Joined: Tue Jun 03, 2003 7:58 am
Location: Greece

[Solved] Array...

Post by dmakris »

Hello to everybody !
I would like to create an array to store some data in.
Is there any way to keep the array visible (global) ?
Thanks in advance...
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

If you keep the array within a file that is included on all of the pages, yes.

It's often done for configuration settings.

eg.

Code: Select all

<?php
// config.inc.php
$config['admin'] = "root";
$config['slogan'] = "fear me for i am root!";
?>
on all your pages

Code: Select all

<?php
include ("config.inc.php");

echo $config['admin'];
?>
Note: in functions you need to just go global $config, and not global $config['admin'] to access a variable. :)
dmakris
Forum Newbie
Posts: 11
Joined: Tue Jun 03, 2003 7:58 am
Location: Greece

re:

Post by dmakris »

Really thanks for your help guys.
Solved in minutes !
Post Reply