Re: multi-dimensional arrays

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I think the best way would be:

$arrays = explode(PHP_EOL, $field);
foreach ($arrays as &$array) {
    $array = explode(" ", $array);
}

Not tested, but should work.


"Andres Gonzalez" <andres@xxxxxxxxxxxxxxx> escreveu na mensagem 
news:49E38A9E.3090600@xxxxxxxxxxxxxxxxxx
> Hi,
>
> I am learning PHP and have a simple question.
> I have a input string in this form:
>
> xxx  xxxx  xx  xxxxx  xx   xxx
> xx  xxxxx   x  xxx  xx  xxxxxx
>     .
>     .
>     .
> xx  xxx  xx  xxxx  xx   xx
>
> each line has 6 words of various lengths, all separated by white space.
> the input string can have any number of lines
>
> I want to put this into a multi-dimensional array, each line an array that 
> is an element of an outer array.
>
> I have tried various ways to do this--I have used explode() and 
> array_filter() and can get a single line parsed and into an array but I am 
> having problems getting a well formed 2 dim array.
>
> What is the easiest way to do this? With all of the PHP array functions, 
> there should be an very straight forward way to do this.
>
> Any help would be appreciated.
>
> -Andres
>
>
> 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux