| Welcome to WebmasterWorld Guest from 126.96.36.199 |
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
|Pubcon Platinum Sponsor 2014|
|Splitting a array|
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?
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
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.
All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved