I have a file that looks like this (with newlines and weird spacing):
Player: Alive: Score: Ping: Member of Team:
player1 No 16 69 dogs
bug Yes 2 63 insects
name with space No 0 69 cats
bob No 0 69 dogs
How can I grab the first column and turn it into an array?
Desired Output:
$players[1] —-> “player1”
$players[2] —-> “bug”
$players[3] —-> “name with space”
$players[4] —-> “bob”
Here is an approach with Iterators:
You would use it like this:
You can then
foreachover the iterator, e.g.Output:
Or transform the stacked Iterators into an array:
Output:
Demo of above examples with your file’s data