| Splitting a array
|
Matthew1980

msg:4407454 | 9:07 pm on Jan 16, 2012 (gmt 0) | Hi there people, I'm going mad as this to me would seem easy to do, but I cannot fathom this out today:- I read a file:- FIRST_LINE, a value SECOND_LINE, another value THIRD_LINE, yet another value Then that geat read into an array:- FirstArray[0] = "FIRST_LINE, a value" FirstArray[1] = "SECOND_LINE, another value" FirstArray[1] = "THIRD_LINE, yet another value" What I would like to know is, I would really prefer to have this data in this format:- FirstArray[0] = "FIRST_LINE" SecondArray[0] = " a value" FirstArray[1] = "SECOND_LINE" SecondArray[1] = "another value" FirstArray[2] = "THIRD_LINE" SecondArray[2] = "yet another value" I can't see how to achieve this. Anyone would like to tell me why I can't see the wood for the trees please? Cheers, MRb
|
omoutop

msg:4407575 | 7:15 am on Jan 17, 2012 (gmt 0) | if all your data is in that particular format [val1, val2] then try to explode each line. foreach ($line as $data) { $temp = explode(",", $data); $array1[] = $temp[0]; $array2[] = $temp[1]; } note: this method will fail if either [FIRST_LINE] or [value] contain (,) characters
|
Matthew1980

msg:4407577 | 7:34 am on Jan 17, 2012 (gmt 0) | Cheers omoutop, I can't fathom out why I could't work this simple little snippet out! I guess it's because it was Monday and I'm tired ;) That'll do nicely. I'll just tweek it so that I can do it dynamically, but that's cool. Cheers, MRb
|
|
|