title: powershell multi-dimensional array and foreach
body: <p>I use the following statements to populate an array:</p>
  
  <pre><code>for ([int]$i=1; $i -lt 4; $i++)
  {
      for ([int]$j=11; $j -lt 32; $j=$j+10)
      {
           $myRegularArray += ,($i, $j, [int](($i +1) * $j))
      }
  }
  </code></pre>
  
  <p>And the output is pretty much what you'd expect:</p>
  
  <pre><code>foreach ($row in $myRegularArray)
  {
      write-host "$($row[0]) rampant frogs, $($row[1]) horny toads &amp; $($row[2]) bottles of beer"
  }
  
  1 green frogs, 11 horny toads &amp; 22 bottles of beer
  1 green frogs, 21 horny toads &amp; 42 bottles of beer
  1 green frogs, 31 horny toads &amp; 62 bottles of beer
  2 green frogs, 11 horny toads &amp; 33 bottles of beer
  2 green frogs, 21 horny toads &amp; 63 bottles of beer
  2 green frogs, 31 horny toads &amp; 93 bottles of beer
  3 green frogs, 11 horny toads &amp; 44 bottles of beer
  3 green frogs, 21 horny toads &amp; 84 bottles of beer
  3 green frogs, 31 horny toads &amp; 124 bottles of beer
  </code></pre>
  
  <p>However, I use select-object and in some scenarios only a single row is selected from the muti-dimensional array. e.g.</p>
  
  <pre><code>foreach ($row in ($myRegularArray | where-object { $_[2] -eq 124 }))
  {
      write-host "$($row[0]) rampant frogs, $($row[1]) horny toads &amp; $($row[2]) bottles of beer"
  }
  </code></pre>
  
  <p>And now instead the foreach iterates through each object in the arrays single dimension:</p>
  
  <pre><code>3 rampant frogs,  horny toads &amp;  bottles of beer
  31 rampant frogs,  horny toads &amp;  bottles of beer
  124 rampant frogs,  horny toads &amp;  bottles of beer
  </code></pre>
  
  <p>I can sort of see why this happens, and I figure the answer is not to use foreach. I there any way of changing this behaviour so that I can still use foreach?</p>