Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: my brain hurts

  1. #1
    Regular Coder
    Join Date
    Mar 2005
    Posts
    156
    Thanks
    8
    Thanked 1 Time in 1 Post

    my brain hurts

    ok, so i've got an array like this

    PHP Code:
    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.

  • #2
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,273
    Thanks
    4
    Thanked 83 Times in 82 Posts
    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
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #3
    Regular Coder
    Join Date
    Mar 2005
    Posts
    156
    Thanks
    8
    Thanked 1 Time in 1 Post
    Quote Originally Posted by Spookster View Post
    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

  • #4
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,273
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Quote Originally Posted by ziggy1621 View Post
    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.

    Code:
    ---------      ---------     ---------   
    | Node 1 | ->  | Node 2 | -> | Node 3 | 
    ---------      ---------     ---------
       |               |             |
    ---------      ---------     ---------------  
    | Array 1|     | Array 2|    | Linked List | 
    ---------      ---------     ---------------
                                     |
                                 ---------     ---------    
                                 | Node 1 | -> | Node 2 | 
                                 ---------     ---------
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •