title: Foreach in Multi-Dimensional Array
body: <p>I'm trying to practice/learn <em>foreach</em> loops in PHP. I understand basic foreach. But I struggle with multi-dimensionals.</p>
  
  <p>I have an array to test it out:</p>
  
  <pre><code>$data = array(
          array('New York', 'New York City'),
          array('hotel', 'lodging','motel'),
          array('cheap')
      );
  </code></pre>
  
  <p>What I would like to do is loop through each and fine every possible combination &amp; assign it to it's own array (will later be displayed as columns).</p>
  
  <pre><code>First column ('New York', 'New York City')
  second column ('New York hotel', 'New York lodging', 'New York motel')
  third column ('New York City hotel', 'New York City lodging', 'New York City motel')
  fourth column ('New York hotel cheap', 'New York lodging cheap', 'New York motel cheap')
  fifth column ('New York City hotel cheap', 'New York City lodging cheap', 'New York City motel cheap')
  </code></pre>
  
  <p>How would I accomplish this? I've tried a couple things, but haven't even gotten close.</p>
  
  <p><strong>Update</strong>
  My end goal is to have an individual be able to take a list of items, and try to find all possible keywords. This will then help in identifying different SEO keywords that they can consider using.
  So sometimes the Data array may have 2 sub arrays, other times it may have 3 or 4. So it would need to be a bit dynamic.</p>
  
  <p><strong>1st Solution Attempt</strong></p>
  
  <pre><code>public function recurseful($start, $args)
  {
      if (is_array($args))
          {
              foreach ($args[0] as $value)
              {
                  $this-&gt;output[] = trim("{$start} {$value}");
                  if (count($args) &gt; 1)
                  {
                      $this-&gt;recurseful($value, array_slice($args, 1));
                  }
  
              }
          }
      return;
  }
  </code></pre>
  
  <p>However, this returns all of my words in a single array. That does not meet the requirements of what I'm looking for.</p>