0

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
  • Welcome to SO. I don't understand what you mean. Can you show some code? Also, what is $host and what does it have to do with the issue? Commented Oct 12, 2010 at 23:06

3 Answers 3

2
<?php
    $c['example.com-user'] = "someval";
    $host = "example.com";
    echo $c[ $host . '-user'];
?>

Tested, working.

Sign up to request clarification or add additional context in comments.

Comments

1
$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.

1 Comment

damn.. why didn't i think of this earlier
0

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).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.