SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    Sep 2008
    Posts
    111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Find duplicate values in multidimentional array

    Hi to all,

    I have multidimensional array and want find the duplicate values

    Code:
    array(2) {
      [1]=>
      array(3) {
        [0]=>
        string(19) "2013-02-04 02:48:00"
        [1]=>
        string(19) "2013-02-05 08:48:00"
        [2]=>
        string(19) "2013-02-06 21:48:00"
      }
      [2]=>
      array(9) {
        [0]=>
        string(19) "2013-02-04 01:48:00"
        [1]=>
        string(19) "2013-02-04 02:48:00"
        [2]=>
        string(19) "2013-02-04 22:48:00"
        [3]=>
        string(19) "2013-02-05 05:48:00"
        [4]=>
        string(19) "2013-02-05 08:48:00"
        [5]=>
        string(19) "2013-02-05 22:48:00"
        [6]=>
        string(19) "2013-02-06 02:48:00"
        [7]=>
        string(19) "2013-02-06 08:48:00"
        [8]=>
        string(19) "2013-02-06 22:48:00"
      }
      [4]=>
      array(9) {
        [0]=>
        string(19) "2013-02-04 01:48:00"
        [1]=>
        string(19) "2013-02-04 08:48:00"
        [2]=>
        string(19) "2013-02-04 22:48:00"
        [3]=>
        string(19) "2013-02-05 02:48:00"
      }
    }
    I have two database table for example table1 and table2

    table1 has following fields
    Code:
    t1_ID   Start_date
    table2
    Code:
    t2_ID   service_id  t1_ID
    i want to insert the duplicate start_date once in table1 and then the id of that record in table2

    For example in above array

    Code:
    arr[1][0]
    arr[2][1]
    arr[4][3]
    has same start date which is 2013-02-05 02:48:00 i want to put this in table1 once like
    Code:
    t1_ID        start Date
    
    1        2013-02-05 02:48:00
    Now in table2
    Code:
    t2_ID   service_ID     t1_ID
    1              1              1
    2              2              1
    3              4              1
    Its mean in table2 subarray which has duplicate values will be inserted against it along the service id which is the index of the array which we are setting .

    thanks.

  2. #2
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,178
    Mentioned
    63 Post(s)
    Tagged
    2 Thread(s)
    This just seems ugly on many levels. Can we get a 10,000 foot view of what you want to accomplish with this? 1) your array is messy like you've done some manipulation with it first, why? 2) why are you storing dupes in a table at all, let alone two of them?

    I think we can help you find a cleaner way all around of handling whatever your original problem is if we know a little bit more


Bookmarks

Posting Permissions

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