Web Analytics Made Easy -
StatCounter my brain hurts - CodingForum

Announcement

Collapse
No announcement yet.

my brain hurts

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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.

    Spookster
    CodingForum Supreme Overlord
    All Hail Spookster

    Comment


    • #3
      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

      Comment


      • #4
        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
        CodingForum Supreme Overlord
        All Hail Spookster

        Comment

        Working...
        X
        😀
        🥰
        🤢
        😎
        😡
        👍
        👎