473,327 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

more about arrays

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)
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...)
Jul 17 '05 #1
2 1483
With total disregard for any kind of safety measures "deko"
<dj****@hotmail.com> leapt forth and uttered:
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)
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...)


Maybe you should consider looking at serialize()

--
Phil Roberts | Dork Pretending To Be Hard | http://www.flatnet.net/
Jul 17 '05 #2
deko wrote:
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) Do you mean 0-3? :)
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...)


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 :
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Markus Dehmann | last post by:
I have n sets of elements. I want to find elements that occur more than once in more than one set. Maybe the following example shows what I mean: S1 = {1,2,3,2,4} S2 = {2,2,4,5,4} S2 =...
0
by: adavidso | last post by:
I am a bit of a newbie to python, and would like a little advice on how to more efficiently process arrays. I work a lot with satellite data, and have opened and read two binary images into...
5
by: Arjen | last post by:
Hello, I have an array "aPeople" with people objects which I serialize like this: XmlSerializer x = new XmlSerializer( typeof(People) ); TextWriter writer = new StreamWriter( "data.xml" );...
5
by: JezB | last post by:
What's the easiest way to concatenate arrays ? For example, I want a list of files that match one of 3 search patterns, so I need something like DirectoryInfo ld = new DirectoryInfo(searchDir);...
1
by: Rob Griffiths | last post by:
Can anyone explain to me the difference between an element type and a component type? In the java literature, arrays are said to have component types, whereas collections from the Collections...
5
by: akameswaran | last post by:
Disclaimer - I recognize this is not a practical exercise. There are many implementations around that would do the job better, more efficiently (Meaning in C) or whatever. I caught some thread...
6
by: Robert Bravery | last post by:
Hi all, Can some one show me how to achieve a cross product of arrays. So that if I had two arrays (could be any number) with three elements in each (once again could be any number) I would get:...
4
by: Christian Maier | last post by:
Hi After surfing a while I have still trouble with this array thing. I have the following function and recive a Segmentation fault, how must I code this right?? Thanks Christian Maier
1
by: Doug_J_W | last post by:
I have a Visual Basic (2005) project that contains around twenty embedded text files as resources. The text files contain two columns of real numbers that are separated by tab deliminator, and are...
29
weaknessforcats
by: weaknessforcats | last post by:
Arrays Revealed Introduction Arrays are the built-in containers of C and C++. This article assumes the reader has some experiece with arrays and array syntax but is not clear on a )exactly how...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.