#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2008
    Posts
    67
    Rep Power
    0

    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

    t1_ID start Date

    1 2013-02-05 02:48:00


    Now in table2

    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
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2010
    Posts
    89
    Rep Power
    5
    Could you not change the table structure to include a third table and create a many to many relationship, so you can see every entry as unique, and then do your filtering from this?

    volterony

IMN logo majestic logo threadwatch logo seochat tools logo