deko wrote:[color=blue]
> Is it possible to read a multi-dimensional array from a file? How would one
> represent a multi-dimensional array in a flat file? Is this possible? For
> example, I want to have 3 elements in the array, each of which is an array
> itself:
>
> Element 1
> ARRAY (1-4)[/color]
Do you mean 0-3? :)
[color=blue]
> Element 2
> ARRAY (1-120)
> Element 3
> ARRAY (1-1460)
>
> I'd like to store this array in a delimitated flat file - all integers.
>
> 3|84|753|2|0|349|5|0| ... and so on
>
> perhaps I need 2 files? other options? (I know... get a database...)[/color]
If each element is separated by "|" and each array separated by newlines
I'd try this:
<?php
$lvl1 = explode("\n", file($filename));
// $lvl1[0] contains the first line of $filename
// $lvl1[1] contains the second line
// ...
foreach ($lvl1 as $k=>$line) {
$lvl2[$k] = explode("|", $line);
}
// $lvl2[0] is an array
// $lvl2[0][0] contains the first integer in the first line
// $lvl2[0][1] contains the second integer in the first line
// ...
// $lvl2[1][0] contains the first integer in the second line
?>
--
USENET would be a better place if everybody read: : mail address :
http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
http://www.expita.com/nomime.html : to 10K bytes :