title: Powershell: Two dimension arrays
body: <p>The following works as expected:</p>
  
  <pre><code>$values = @( ("a", "b"), ("c", "d") )
  foreach($value in $values)
  {
    write-host "Value 0 =" $value[0]
    write-host "Value 1 =" $value[1]
  }
  </code></pre>
  
  <p>which results(1) in:</p>
  
  <pre><code>Value 0 = a
  Value 1 = b
  Value 0 = c
  Value 1 = d
  </code></pre>
  
  <p>But if I change the $values variable to:</p>
  
  <pre><code>$values = @( ("a", "b") )
  </code></pre>
  
  <p>the result(2) is:</p>
  
  <pre><code>Value 0 = a
  Value 1 =
  Value 0 = b
  Value 1 =
  </code></pre>
  
  <p>whereas I would have expected the result(3) to be:</p>
  
  <pre><code>Value 0 = a
  Value 1 = b
  </code></pre>
  
  <p>Changing the $value to:</p>
  
  <pre><code>$values = @( ("a"), ("b") )
  </code></pre>
  
  <p>gives the same result as result(2) above.  These are very different data representations.</p>
  
  <p>The script that I am writing needs to be able to handle two-dimensional arrays where the first dimension has length from 0 thru N.  I would like to be able to write the script so that if a first-level element needs to be added (or removed) that I don't have to change the logic of the script; I'd like to be able to just edit the "data".</p>
  
  <p>So my question is: How do I notate a two-dimensional array so the shown <strong>foreach</strong> loop will work correctly when the first dimension of the array has a length of 1?</p>
  
  <p>get-host responds with:</p>
  
  <pre><code>Name             : ConsoleHost
  Version          : 2.0
  InstanceId       : 2338657f-e474-40d8-9b95-7e2b5f6a8acf
  UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
  CurrentCulture   : en-US
  CurrentUICulture : en-US
  PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
  IsRunspacePushed : False
  Runspace         : System.Management.Automation.Runspaces.LocalRunspace
  </code></pre>