Combine Individual Items From Separate Arrays Into a Third Array


i have 2 arrays, 1 list of first names , second list of last names. combine first name , last name reside @ same index position in respective arrays third array. each pair of arrays have same number of items, number may change - i.e., in instances there may 5 first names , 5 last names, @ other times there may 15 first names , 15 last names.

so, example:

array $firstname contains:
$firstname[0] = jon
$firstname[1] = bob
$firstname[2] = tom

array $lastname contains:
$lastname[0] = smith
$lastname[1] = jones
$lastname[2] = white

and want create array $fullname this...
$fullname[0] = jon smith
$fullname[1] = bob jones
$fullname[2] = tom white

thanks help.

if know first , last names in correct order, can this.

$firstname = @('jon','bob','tom') $lastname = @('smith','jones','white') $fullname = @() ($i = 0; $i -lt $firstname.count; $i++) {     $fullname += "$($firstname[$i]) $($lastname[$i])" } $fullname

more reading on loops: http://ss64.com/ps/for.html



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

Edit Group Policy

Hyper-V VM not reaching OS 'Logon' screen

DNS question...