title: How can I return the position a nested array is in, from the value of the first element?
body: <p>Hopefully that title makes sense! </p>
  
  <p>I have an array, which is made up of 48 sets of 3 numbers. What I now want to do is print these sets of 3 numbers in a pre-defined order, based on the first number in that set of 3. The sub-array is like so:</p>
  
  <pre><code>@($label, $number1, $number2)
  </code></pre>
  
  <p>There will be 48 sets of these, the label is always unique and is pulled from the title of a CSV file. (The CSV files are fed through various PowerShell scripts to tidy their titles and convert them to XLS, and to run various macros on.) They go through in file order, but I want to print them out in another pre-defined order of my choosing.</p>
  
  <p>So in order to print them in the order of label I would like, I need to be able to test the $label part of the sub-array. If it matches the label I want, print the set of 3 out.</p>
  
  <p>To test my code so far I have constructed a loop that populates my array:</p>
  
  <pre><code>$results = @(1 .. 48)
  
  $label = 148
  $var1 = 5
  $var2 = 3
  
  for($i = 0; $i -le 47; $i++) {
      $results[$i] = @($label, $var1, $var2)
  }
  </code></pre>
  
  <p>What I need to do now is print these sets of 3 in a particular order, which I will dictate by the label. The next section of code will probably just be a custom function like posArray($label). As I type this out I realise it would be just as useful to print the part of the array with the label in, it doesn't have to necessarily tell me which position it is.</p>
  
  <p>Please feel free to suggest better ways to architect this if possible. It must run in PowerShell though. I thought about maybe a hash, but as it's two vars not just a pair I wasn't sure.</p>
  
  <p>I've tried to go back round the loop and check the first element in each of the nested arrays, but it prints out "System.Object[]" a load of times.</p>
  
  <pre><code>for($i = 0; $i -le 47; $i++) {
      if($results[$i][0] -eq $label) {
          Write-Host "$results[$i]"
      }
  }
  </code></pre>
  
  <p>So I'm not really sure what's happening there.</p>
  
  <p>Ideally if this was the case (the for loop searching and printing the 1 set by $label) I'd put the loop in a function, call the function by FunctionName($label) and I would call the function a bunch of times with the labels in my desired order.</p>
  
  <p>Essay over...</p>