Forum Discussion
read elements of an array simultaneously
Thanks for your reply Vasil, here is what I have (sample code)
$testarray = ("a", "b", "c", "d")
foreach ($x in $testarray) {
print $x
}
This loop actually iterates this array and prints
a
b
c
d
Now I wanted to perform it in a way that this print statement is executed on all elements at once and so that result is like
a b c d
Hi,
You can achieve this by "join" method.
$testarray = ("a", "b", "c", "d")
$testarray -join " "
#For comma separated values
$testarray -join ","
- rahulrunsFeb 20, 2019Copper Contributor
Thank you for your reply, I will try to be clearer on what I intent to do. $testarray (with join it will have field separators) will print array but will not help me do a simultaneous operation on all elements of an array. What I wrote is just sample where if I replace print statement with anything else it should work on all elements simultaneously
- VasilMichevFeb 20, 2019MVP
What exactly are you trying to do?
- rahulrunsFeb 21, 2019Copper Contributor
Hi Vasil,
I have a function that performs some operation on each element of an array. Now these operations are independent and not required to be done simultaneously. I am trying to work out a method that how function can act on all these elements at same time