Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In your question you say you have a multidimensional array, so I take it is like this:</p> <pre><code>$config = array('foo' =&gt; array('bar' =&gt; array('baz' =&gt; 3))); </code></pre> <p>Calling <code>item('foo', 'bar', 'baz')</code> would run all the way through to the last array and return 3. If that is what you want, you could just write <code>$config['foo']['bar']['baz']</code> or place your configs in an <a href="http://de.php.net/manual/en/class.arrayobject.php" rel="nofollow noreferrer">ArrayObject</a> and use either the array access notation or <code>$config-&gt;foo-&gt;bar-&gt;baz</code> (though all nested arrays must be ArrayObjects too then). </p> <p>If you want to keep the function, you should add some checking on the index before you grab it, because PHP will raise a Notice about undefined indexes. In addition, why not use <a href="http://de.php.net/manual/en/class.invalidargumentexception.php" rel="nofollow noreferrer">InvalidArgumentException</a> instead of Exception. Fits better for this case.</p> <p><em>edit: removed some portion of the answer, because it was more like loud thinking</em></p> <p><em>edit after comments</em><br/> Tbh, I find it a rather awkward approach to reinvent array access through a method like this. In my opinion you should either pass the entire config or a subset to your objects during construction and let them take whatever they need through the regular array accessors. This will <a href="http://en.wikipedia.org/wiki/Dependency_inversion_principle" rel="nofollow noreferrer">decouple</a> your objects from your configManager and allows for easier modification at a later point.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload