...

View Full Version : my brain hurts



ziggy1621
08-26-2011, 09:24 PM
ok, so i've got an array like this



Array
(
[someURL] => Array
(
[0] => Array
(
[2011-08-24] => 10
)

[1] => Array
(
[2011-08-25] => 20
)
)
[secondURL] => Array
(
[0] => Array
(
[2011-08-24] => 10
)
)



and what I am trying to do is strip down the array and rewrite it to add an entry of 0 for the second url and date 2011-08-25 since there is no value. All of the URL dimensions of the array need to have the same amount of data for what I'm trying to accomplish. So I need to be able to go through the array and make sure that each URL reference has the same dates available as the rest of the URLs and if not, add one with a 0 as the value.

I've been trying for a couple of hours and think I'm at the point where I am going nuts.

Spookster
08-26-2011, 10:29 PM
Why don't you just initialize the array with all the possible elements you might need and just set all the initial values to zero and then just use the elements you do need?

Or go with some kind of other data structure that best supports what you need it to do. A basic array is not really intended to be used in the manner of "restructuring" it. A linked list would probably be better suited for what you are describing.

http://en.wikipedia.org/wiki/Linked_list

ziggy1621
08-27-2011, 03:11 AM
Why don't you just initialize the array with all the possible elements you might need and just set all the initial values to zero and then just use the elements you do need?

Or go with some kind of other data structure that best supports what you need it to do. A basic array is not really intended to be used in the manner of "restructuring" it. A linked list would probably be better suited for what you are describing.

http://en.wikipedia.org/wiki/Linked_list


I'm sure what you are saying is correct, but do you have a better reference? I cant find any real world examples of it used. I found some classes to create them, but I'd like to understand them a bit before jumping in

Spookster
08-27-2011, 11:36 PM
I'm sure what you are saying is correct, but do you have a better reference? I cant find any real world examples of it used. I found some classes to create them, but I'd like to understand them a bit before jumping in


What would you like to know about them? It's a fundamental building block for any data structure. You can create a linked list with each node being a reference to another structure like an array or even another linked list. Allows you to have a structure that you can easily add to or remove things from without having to know how big it needs to be.

As as an example. You can add a mix of arrays or other linked lists to each node.



--------- --------- ---------
| Node 1 | -> | Node 2 | -> | Node 3 |
--------- --------- ---------
| | |
--------- --------- ---------------
| Array 1| | Array 2| | Linked List |
--------- --------- ---------------
|
--------- ---------
| Node 1 | -> | Node 2 |
--------- ---------



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum