473,788 Members | 2,814 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"Collapse" a file using PHP array?

For lack of a better term I wish to collapse a data file as so:

03/01/04|item1|3081|| |
03/01/04|item2|2081|| |
03/01/04|item3|1195|| |

03/01/04|item1||556||
03/01/04|item2||450||
03/01/04|item3||397||

03/01/04|item1|||434|
03/01/04|item2|||544|
03/01/04|item3|||232|

03/01/04|item1||||343
03/01/04|item2||||545
03/01/04|item3||||433

so that it would read:

03/01/04|item1|3081|5 56|434|343
03/01/04|item2|2081|4 50|544|545
03/01/04|item3|1195|3 97|232|433

(data would extend beyond 03/01/04, so subsequent dates must be taken into
account)

My idea is to import into an array, and then "collapse" it somehow - but
how? Is it possible without numerious iterations?

Many thanks in advance.

Jul 17 '05 #1
2 1883
DesignGuy wrote:
For lack of a better term I wish to collapse a data file as so:

03/01/04|item1|3081|| |
03/01/04|item2|2081|| |
03/01/04|item3|1195|| |

03/01/04|item1||556||
03/01/04|item2||450||
03/01/04|item3||397||

03/01/04|item1|||434|
03/01/04|item2|||544|
03/01/04|item3|||232|

03/01/04|item1||||343
03/01/04|item2||||545
03/01/04|item3||||433

so that it would read:

03/01/04|item1|3081|5 56|434|343
03/01/04|item2|2081|4 50|544|545
03/01/04|item3|1195|3 97|232|433

(data would extend beyond 03/01/04, so subsequent dates must be taken into
account)

My idea is to import into an array, and then "collapse" it somehow - but
how? Is it possible without numerious iterations?

Many thanks in advance.


Check out http://ca2.php.net/fgetcsv

It should allow you to read the file in to an array without conversion -
It expects a comma as a field seperator, however if your data above is
exact, you should tell tell it that you have the pipe character as
delimiter.

randelld
Jul 17 '05 #2
DesignGuy wrote:
For lack of a better term I wish to collapse a data file as so:

03/01/04|item1|3081|| |
03/01/04|item2|2081|| | (snip)
so that it would read:

03/01/04|item1|3081|5 56|434|343
03/01/04|item2|2081|4 50|544|545
03/01/04|item3|1195|3 97|232|433

(data would extend beyond 03/01/04, so subsequent dates must be taken into
account)

My idea is to import into an array, and then "collapse" it somehow - but
how? Is it possible without numerious iterations?

Using fgetcsv() or some other file reading function I'd try to put that
data into an array of arrays with the format

$arr['03/01/04']['item1'][0] = 3081;
$arr['03/01/04']['item1'][1] = 556;
$arr['03/01/04']['item1'][2] = 434;
$arr['03/01/04']['item1'][3] = 343;

$arr['03/01/04']['item2'][0] = 2081;
$arr['03/01/04']['item2'][1] = 450;
$arr['03/01/04']['item2'][2] = 544;
$arr['03/01/04']['item2'][3] = 545;

....

and after that, to write the array to another file, I'd use foreach()
and implode()

foreach ($arr as $dat=>$items) {
foreach ($items as $item=>$data) {
echo $dat, '|', $item, '|', implode('|', $data);
}
}
Check these functions at the manual:
http://www.php.net/fgetcsv
http://www.php.net/foreach
http://www.php.net/implode
HTH
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #3

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

Similar topics

42
2627
by: Alan McIntyre | last post by:
Hi all, I have a list of items that has contiguous repetitions of values, but the number and location of the repetitions is not important, so I just need to strip them out. For example, if my original list is , I want to end up with . Here is the way I'm doing this now: def straightforward_collapse(myList):
5
14782
by: Rolf Brauser | last post by:
Hi, I want to have a table with a border of 1px arround it but table="1" is more than a pixel because this 3d effect is attached. Values below are not accepted How can I get this border with 1px can someone give me any hints ? thanks for any help
3
5624
by: Robert Oschler | last post by:
I have an IFrame on my web pages that displays useful tips. I have a button next to it that hides and shows it by triggering a Javascript call. I know how to make the iframe invisible by changing it's "visibility" property, and I know how to change it's size using the style "height" property. The problem is, with both of those techniques the IFRAME still occupies the same amount of real estate as before, even if it's now invisible /...
15
2851
by: Sander Tekelenburg | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 The HTML specs speak of "replaced" and "non-replaced" elements, yet for the life of me I can't find an explanation of what "replaced" is supposed to mean in this context. Can someone explain? TIA
2
3005
by: Paul Malcomson | last post by:
Hi. I'm having terrible trouble with a form that displays several parent/child relationships at one time. It is a sales force hierarchy - Sales force, district, territory, sales rep are the tables linked in parent/child relationships. I'm using a form to choose the main-parent and then several subforms in datasheet view.
22
12993
by: Alan Silver | last post by:
Hello, I am updating some old web pages, and have come across a problem. I have some tables where the opening tag looks like... <table border="1" bordercolor="#ffffff"> which gives a nice flat border around the table in IE, and a fairly unpleasant (IMO) 3D-effect border in Firefox.
2
4750
by: spifster | last post by:
Hello all, I am building a collapsable tree using Javascript with DOM in IE. In order to make collapsed cells disappear I have been hiding the text. The cells collapse but still leave borders behind. I have set the borderStyle to none and the black lines go away, but there is still white space where the borders were. Following are my html files I am using to test it. ----------------BEGIN HTML FILE----------------
4
768
by: Chicagoboy27 | last post by:
All I am trying to find a solution for removing the ?returnUrl if a user is not authenticated. I want to be redirect an unauthenticated user to the login.aspx less the returnUrl. Once they log in I specifically want them to go to the default.aspx page and not the "ReturnUrl=" page. currently my sight is set up to redirect to the log in but I am looking to remove the ?returnurl so that it goes to the normal defualt.aspx Currently I am...
7
1982
by: schoenfeld.one | last post by:
Most people don't know that there were actually 3 buildings which came crashing down on the day of 9/11. The third building, WTC 7, can be seen here http://video.google.com/videoplay?docid=-7750532340306101329 There is no mention of this building in 911 Omission Report. Can fire make a building come crashing down at free fall speed?
0
9656
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9498
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10366
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10173
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8993
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7517
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5399
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.