I'm looking to cross combine values of arrays to create new array. example,
$a = @('Blue','red','green')
$b = @('car', 'bike')
to something like
('blue car','red car','green car') and ('blue bike','red bike','green bike')
PS: this is not simple concatenate function I'm looking.
Thanks, Nilay
$outArrays[0]now contains'blue car', 'red car', 'green car'$outArrays[1]now contains'blue bike', 'red bike', 'green bike'The above takes advantage of PowerShell's ability to use loop statements such as
foreachas expressions, with PowerShell implicitly collecting all outputs from the loop in an array ([object[]]; assuming two or more outputs).General information about array concatentation:
To create a flat array, by concatenation, simply use
+:To create a two-element nested array, use the unary form of
,, the array constructor operator:As an aside: note that you don't strictly need
@(...), the array-subexpression operator to create array literals; e.g.,$a = 'Blue', 'red', 'green'will do.