473,246 Members | 1,536 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,246 software developers and data experts.

Multi-dimensional arrays, wildcards

Hi guys,

I've got an array question. I've searched, but maybe I just can't
figure out the best way to phrase the question to Google or groups, so
I'll try here.

I've got a multi-dimensional array that resolves out to look like this:

Array
(
[2004-48] => Array
(
[linesadded] => 122
[linesdeleted] => 4
)

[2004-49] => Array
(
[linesadded] => 28
[linesdeleted] => 23
)

[2004-50] => Array
(
[linesadded] => 18
[linesdeleted] => 5
)

[2004-51] => Array
(
[linesadded] => 178
[linesdeleted] => 38
)
)

(but quite a bit longer)

The first level key is the year and week of year. Eg, 2004-51 is the
51st week of 2004. The two second level items are what I want to give
to an array function. I'm doing some graphs, and I used to just hand
an array of values off (eg, $array=(23,25,14,23,53) and so on) and then
pass a second array that was the list of weeks in order that attach to
each data point.

I want to re-write my function to store the data keyed off date in the
array so I can do a bunch of other stuff with it without seperating the
keys from the data itself.

The challenge that I have is to, without faking it and generating
secondary arrays to use as temps, pass variations of this main array to
two different functions. One time, I want it to give a list of the
keys (to use as the tick interval on the chart) which is the first
level key, and the other function, I want to be able to disgorge, in
the order of the array, the values of all 'linesadded' or
'linesdeleted' as an array.

I assumed (whoops) that it would be as easy as, for the latter, do
something like this:

$linesadded = $VelocityData[]['linesadded']
$linesdeleted = $VelocityData[]['linesdeleted']
and for the axis
$timeaxis = array_keys($VelocityData);

It seems to be a bit more complicated. Any suggestions? If there's a
rudimentary bit of array logic that I'm missing, lemme know. If I'm
making things way too hard for myself, let me know that I'll work
around it, but it'd sure be nice to keep the keys and data together.

Thanks!

Jul 17 '05 #1
1 2180
On 23 May 2005 14:32:32 -0700, Ben Hallert wrote:
The two second level items are what I want to give
to an array function.


You need to transpose the array:

foreach ( $a as $k1 => $v1 )
foreach ( $v1 as $k2 => $v2 )
$b[$k2][$k1] = $v2;

Then use $b['linesadded'].
--
Firefox Web Browser - Rediscover the web - http://getffox.com/
Thunderbird E-mail and Newsgroups - http://gettbird.com/
Jul 17 '05 #2

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

Similar topics

37
by: ajikoe | last post by:
Hello, Is anyone has experiance in running python code to run multi thread parallel in multi processor. Is it possible ? Can python manage which cpu shoud do every thread? Sincerely Yours,...
4
by: Frank Jona | last post by:
Intellisense with C# and a multi-file assembly is not working. With VB.NET it is working. Is there a fix availible? We're using VisualStudio 2003 Regards Frank
12
by: * ProteanThread * | last post by:
but depends upon the clique: ...
0
by: frankenberry | last post by:
I have multi-page tiff files. I need to extract individual frames from the multi-page tiffs and save them as single-page tiffs. 95% of the time I receive multi-page tiffs containing 1 or more black...
6
by: cody | last post by:
What are multi file assemblies good for? What are the advantages of using multiple assemblies (A.DLL+B.DLL) vs. a single multi file assembly (A.DLL+A.NETMODULE)?
4
by: mimmo | last post by:
Hi! I should convert the accented letters of a string in the correspondent letters not accented. But when I compile with -Wall it give me: warning: multi-character character constant Do the...
5
by: Shane Story | last post by:
I can seem to get the dimensions of a frame in a multiframe tiff. After selecting activeframe, the Width/Height is still really much larger than the page's actual dimensions. When I split a...
5
by: bobwansink | last post by:
Hi, I'm relatively new to programming and I would like to create a C++ multi user program. It's for a project for school. This means I will have to write a paper about the theory too. Does anyone...
0
by: Sabri.Pllana | last post by:
We apologize if you receive multiple copies of this call for papers. *********************************************************************** 2008 International Workshop on Multi-Core Computing...
1
by: mknoll217 | last post by:
I am recieving this error from my code: The multi-part identifier "PAR.UniqueID" could not be bound. The multi-part identifier "Salary.UniqueID" could not be bound. The multi-part identifier...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
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...
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
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
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...

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.