tags:

views:

44

answers:

3

Hi, I have a config file which has variables based on the domain of the page (HTTP_HOST)

$c is an array.
eg $c['example.com-user'] is an entry in the config file.

I need to pass the value of $c['example.com-user'] to a function building the variable name on the fly.

I have "example.com" in $host variable

Thanks for any help!

+1  A: 
$c[$host.'-user']

Assuming you only ever need the config data for the current domain, might it be easier to have a config file per domain, rather than one monster array with all of them? Then you can just load up the relevant file at the start.

Tim Fountain
damn.. why didn't i think of this earlier
aspen7
+2  A: 
<?php
    $c['example.com-user'] = "someval";
    $host = "example.com";
    echo $c[ $host . '-user'];
?>

Tested, working.

Ruel
A: 

If, for example your domain stored in variable $host and username in variable $user. Then, all you have to do is, use this variables as array's key:

echo $c[ $host . "-" . $user];

if $host = 'inform.com' and $user = 'simple_user', the code above will translate into:

echo $c['inform.com-simple_user'];

You see, to concatenate string, you use '.' (dot).

silent