title: How to feed a PHP function a multidimensional array that might not be set at any depth, and check if it's set inside the function. (Tutorial)
body: <p><strong>Explanation of the problem</strong></p>
  
  <p>A PHP function is normally called in the following manner:</p>
  
  <pre><code>myFunction($parameter);
  </code></pre>
  
  <p>If $parameter isn't set though, PHP will throw an error. A solution to that would be doing it as follows:</p>
  
  <pre><code>if (isset ($parameter))
  {
      myFunction($parameter);
  }
  </code></pre>
  
  <p>However, it can get really annoying to have to use an if() check every time you wanted to call that function and are unsure if it's set. The first thing I thought was declaring the function like so:</p>
  
  <pre><code>function myFunction($local)
  {
      if(isset($local))
      {
          //Code goes here.
      }
  }
  </code></pre>
  
  <p>But calling the function didn't work, as PHP doesn't seem to support feeding unset variables to a function as a parameter. To get around this, I used variable variables:</p>
  
  <pre><code>function myFunction($local)
  {
      if(isset(${$local})
      {
          //Code goes here.
      }
  }
  
  myFunction('parameter');
  </code></pre>
  
  <p>To see how variable variables work, refer to the <a href="http://php.net/manual/en/language.variables.variable.php" rel="nofollow">PHP Manual</a>.</p>
  
  <p>This was working fine, until I needed to make checks on array indexes. To solve this, I created a different function to work on arrays that are certain to be set:</p>
  
  <pre><code>myFunctionArray($array,$key)
  {
      if(isset($array[$key]))
      {
          //Code goes here.
      }
  }
  $variable = array();
  myFunctionArray($parameter,'key');
  </code></pre>
  
  <p>In this case, since $variable is set, and 'key' is a harmless string, there will be no errors despite $variable[$key] not being set, and you can successfully make the isset check inside the function. However, this obviously doesn't support multidimensional arrays. To give support to multidimensional arrays, one would have to add more parameters to the function in anticipation to the number of dimensions the array is expected to have. Either of these two functions could work:</p>
  
  <pre><code>myFunctionMultiArray($array,$key1,$key2,$key3)
  {
      if(isset($array[$key1][$key2][$key3]))
      {
          //Code goes here.
      }
  }
  myFunctionMultiArray2($array,$keys)
  {
      if(isset($array[$keys[0]][$keys[1]][$keys[2]]))
      {
          //Code goes here.
      }
  }
  $variable = array();
  myFunctionMultiArray($parameter,'key1','key2','key3');
  myFunctionMultiArray2($parameter,array('key1','key2','key3');
  </code></pre>
  
  <p>Another problem, now we're getting our hands full with functions, one for each array depth. How do we make it so that the function can be fed an array with any depth?</p>