How to add duplicates from one array to another array.
Posted: Wed Sep 12, 2007 4:31 pm
Okay,
I have an associative array called $isPrinted that has some duplicate information.
I need to make another array that holds all the duplicates of $isPrinted. I only need the duplicates of $isPrinted added once to the new array.
How do I do this? I need this for comparison later on in the code.
As an example:
the $isPrinted array is:
Array (
[0] => Array ( [section] => 2 [courseNum] => 9 )
[1] => Array ( [section] => 1 [courseNum] => 3 )
[2] => Array ( [section] => 1 [courseNum] => 7 )
[3] => Array ( [section] => 2 [courseNum] => 3 )
[4] => Array ( [section] => 2 [courseNum] => 10)
[5] => Array ( [section] => 3 [courseNum] => 9 )
[6] => Array ( [section] => 1 [courseNum] => 3 ) /*duplicate*/ This should be added to the new array
[7] => Array ( [section] => 1 [courseNum] => 3 ) /*duplicate*/ only once.
)
I need the new array to contain only duplicates of $isPrinted. So the new array should read:
Array (
[0] => Array ( [section] => 1 [courseNum] => 3 )
)
I have an associative array called $isPrinted that has some duplicate information.
I need to make another array that holds all the duplicates of $isPrinted. I only need the duplicates of $isPrinted added once to the new array.
How do I do this? I need this for comparison later on in the code.
As an example:
the $isPrinted array is:
Array (
[0] => Array ( [section] => 2 [courseNum] => 9 )
[1] => Array ( [section] => 1 [courseNum] => 3 )
[2] => Array ( [section] => 1 [courseNum] => 7 )
[3] => Array ( [section] => 2 [courseNum] => 3 )
[4] => Array ( [section] => 2 [courseNum] => 10)
[5] => Array ( [section] => 3 [courseNum] => 9 )
[6] => Array ( [section] => 1 [courseNum] => 3 ) /*duplicate*/ This should be added to the new array
[7] => Array ( [section] => 1 [courseNum] => 3 ) /*duplicate*/ only once.
)
I need the new array to contain only duplicates of $isPrinted. So the new array should read:
Array (
[0] => Array ( [section] => 1 [courseNum] => 3 )
)