So what I am trying to do is read through a document that looks like this.
testA phaseA 5
testA phaseB 3
testA phaseA 4
testB phaseA 4
so right now, it's going to read through the document line by line and exploding it. I want it to be able to put the information in a multidimensional array looking something like this -
array(
-
[0]=>testA array(
-
[0]=>phaseA = 9,
-
[1]=>phaseB = 3
-
),
-
[1]=>testB array(
-
[0]=>phaseA = 4
-
)
-
)
-
So basically, if it sees that the test and phase already exists, it just adds the number of hours to the previous number. Any help would be appreciated. I'm not sure how to go about this. A sample code would probably be helpful. Ultimately, after writing this array, I need to be able to print out the number of hours of each phase as well as the total number of hours for each test(adding up all the hours for each phase in it). Thanks so much!=)
3 1770
I'm feeling generous today, here you go buddy: -
-
$file = array("testA phaseA 5","testA phaseB 3","testA phaseA 4","testB phaseA 4");
-
$resultArray = array();
-
-
foreach ($file as $line) {
-
list($test, $phase, $value) = explode (" ",$line);
-
-
$resultArray[$test][$phase] += $value;
-
-
}
-
-
print_r($resultArray);
-
-
outputs: -
-
Array
-
(
-
[testA] => Array
-
(
-
[phaseA] => 9
-
[phaseB] => 3
-
)
-
-
[testB] => Array
-
(
-
[phaseA] => 4
-
)
-
-
)
-
-
go nuts,
Dan
hm..so im trying it out with my coding rite now and actually..my document was more like
testA.phaseA=3.0 % testing
for each line.
which is why i couldnt just separate it with exploding spaces. But I did manage to separate them and all of them have a different variable name. Unfortuatnely, when I run my coding, it only shows testB. I believe it overwrote my previous data? Here is my coding. -
$parts2=explode(' % ',$invalidcheck);
-
$parts3=explode('=', $parts2[0]);
-
$parts4=explode('.', $parts3[0]);
-
list($project, $phase) = $parts4;
-
$project=$parts4[0];
-
$phase=$parts4[1];
-
$description=$parts2[1];
-
$hours=$parts3[1];
-
$database=array();
-
$database[$project][$phase]+=$hours;
-
nvm..it works now. I initialized my array at the wrong spot.=P
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Golf Nut |
last post by:
I am finding that altering and affecting values in elements in
multidimensional arrays is a huge pain in the ass. I cannot seem to find a
consistent way to assign values to arrays. Foreach would...
|
by: Terry |
last post by:
Hi,
can someone plz tell me how multidimensional arrays (like a 2-D array)
are stored in memory? Are they like single dimensional arrays? Stored
sequentially in one "row", so to say?
Thanks
...
|
by: Charles Banas |
last post by:
i've got an interesting peice of code i'm maintaining, and i'd like to
get some opinions and comments on it, hopefully so i can gain some
sort of insight as to why this works.
at the top of the...
|
by: Scott Handojo |
last post by:
Lets say I have the following arrays
X1 (1, 2, 7, 8)
X2 (1, 2, 4, 6)
X3 (1, 2, 3, 5)
X4 (1, 3, 5)
X5 (2, 3, 5)
X6 (4, 5, 6, 8)
My 'search array' is comprised of
|
by: Claire |
last post by:
I have a multidimensional array defined as
private double myArray = new double;
The first column of the array contains X values, the other contains Y values
I have a charting function defined as...
|
by: Ravi Singh (UCSD) |
last post by:
Hello all
I am trying to use jagged and multi-dimensional arrays in C++.
In C# these work fine
// for jagged arrays
string jaggedArray = new string ;
//for multidimensional arrays
string...
|
by: utab |
last post by:
Hi there,
Is there a way to convert a double value to a string. I know that there
is fcvt() but I think this function is not a part of the standard
library. I want sth from the standard if...
|
by: |
last post by:
I'm fairly new to ASP and must admit its proving a lot more unnecessarily
complicated than the other languages I know. I feel this is because there
aren't many good official resources out there to...
|
by: Slain |
last post by:
I need to convert a an array to a multidimensional one. Since I need
to wrok with existing code, I need to modify a declaration which looks
like this
In the .h file
int *x;
in a initialize...
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
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...
|
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...
|
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...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
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...
| |