473,405 Members | 2,354 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,405 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 2187
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...

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.