|Splitting a array|
| 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 = "FIRST_LINE, a value"
FirstArray = "SECOND_LINE, another value"
FirstArray = "THIRD_LINE, yet another value"
What I would like to know is, I would really prefer to have this data in this format:-
FirstArray = "FIRST_LINE"
SecondArray = " a value"
FirstArray = "SECOND_LINE"
SecondArray = "another value"
FirstArray = "THIRD_LINE"
SecondArray = "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?
| 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;
$array2 = $temp;
note: this method will fail if either [FIRST_LINE] or [value]
contain (,) characters
| 7:34 am on Jan 17, 2012 (gmt 0)|
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.