find duplicated values in array and count them

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi all


I need to compare values of multiple arrays, the tricky thing: I can't just
use array_diff, because I also need to count all the occurences and give
them back. The more tricky thing: It's a foreach loop through $arr[x
['comparable value'] while x is 1,4,3,6... so it's not that easy to compare
one item in the array under index 4 with the next one(which is in 3)
because foreach just loops.

The idea is: If two keys of different arrays hold the same value, I want to
just show one entry and tell the same time, how often it occurs(in other
arrays), so I don't show all the entries(as I would, if they weren't the
same.
But it is still a bit more complicated, because: only if the date_s value
lies 7 days from each other, I want to "concatenate" them to one entry +
show the number of occurences.

In the example below, the lessons 18 and 15 fit that need.
so I want them to be shown as:
          [room] : Raum1
          [teacher] : Marianne
          [class] : SundayClass
          starttime : 1099404000 (which is Array[19][date_s])
          endtime : 099418400 + 7*24*60*60 (which is Array[15][date_e])
          occurences : 2
       
eg ---------->
print_r($my_big_array) shows:

Array
(
    [7] => Array
        (
            [name] => course1
            [comment] => my bad comment
            [lessons] => Array
                (
                    [14] => Array
                        (
                            [room] => Raum2
                            [teacher] => Andrew
                            [class] => Team2
                            [date_s] => 1100796900
                            [date_e] => 1100805000
                        )

                )

        )

    [3] => Array
        (
            [name] => test
            [comment] => testing
            [lessons] => Array
                (
                    [19] => Array
                        (
                            [room] => Raum1
                            [teacher] => Marianne
                            [class] => SundayClass
                            [date_s] => 1099404000
                            [date_e] => 1099418400
                        )

                    [15] => Array
                        (
                            [room] => Raum1
                            [teacher] => Marianne
                            [class] => SundayClass
                            [date_s] => 1099404000 + 7*24*60*60
                            [date_e] => 1099418400 + 7*24*60*60
                        )

                    [13] => Array
                        (
                            [room] => Raum1
                            [teacher] => Peter
                            [class] => Team1
                            [date_s] => 1100798160
                            [date_e] => 1100803500
                        )

                )

        )


-- 
Patrick Fehr
Swiss Federal Institute Of Technology

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux