title: Can the value of an item in a PHP associative array be created from values in the array?
body: <p>I have a config.php as part of a web project which includes a multidimensional associative array.</p>
  
  <pre><code>$config = array(
      "db" =&gt; array(
          "server" =&gt; "localhost",
          "name" =&gt; "mydb",
          "user" =&gt; "user",
          "pwd" =&gt; "password"
      ),
      "urls" =&gt; array(
          "base_url" =&gt; "http://localhost/"
      ),
      # Omitted for brevity
  );
  </code></pre>
  
  <p>Under the 'db' array I'd like to include a key called 'dsn' which would be a PDO DSN string defined within the array itself. The only way I've managed to do this is defining it separately:</p>
  
  <pre><code>$config['db']['dsn'] = 'mysql:host=' . $config['db']['server'] . ';dbname=' .  $config['db']['name'] . ';port=3306';
  </code></pre>
  
  <p>Is there anyway this could be defined in the array itself, like below?</p>
  
  <pre><code>...
  "db" =&gt; array(
      "server" =&gt; "localhost",
      "name" =&gt; "mydb",
      "user" =&gt; "user",
      "pwd" =&gt; "password"
      "dsn" =&gt; #(some value here that uses "server" and "name")
  ),
  ...
  </code></pre>