Organizational Research By

Surprising Reserch Topic

Question:how to merging same values in an array using php?



asked Sep 13, 2013 in PHP by ashish singh
edited Sep 12, 2013
0 votes
13 views



Related Hot Questions

1 Answer

0 votes

 

$array1 = array(1,2,3,4,5,6,7,8,9,10,11,12);
$array2 = array(1,2,3,13);
 
$merged = array_merge($array1,$array2);
 
// output normal array_merge
echo '
After array_merge :
';
print_r($merged);
echo '';
 
// do double flip for merging values in an array
$merged = array_flip($merged);
$merged = array_flip($merged);
 
// Output after
echo '
After Double Flip : 
';
print_r($merged);
echo '';
?>
 
Output ::
 
After array_merge :
Array
(
    [0] => 1
    [1] => 2
    [2] => 3
    [3] => 4
    [4] => 5
    [5] => 6
    [6] => 7
    [7] => 8
    [8] => 9
    [9] => 10
    [10] => 11
    [11] => 12
    [12] => 1
    [13] => 2
    [14] => 3
    [15] => 13
)
 
After Double Flip : 
Array
(
    [12] => 1
    [13] => 2
    [14] => 3
    [3] => 4
    [4] => 5
    [5] => 6
    [6] => 7
    [7] => 8
    [8] => 9
    [9] => 10
    [10] => 11
    [11] => 12
    [15] => 13
)
answered Sep 13, 2013 by ashish singh
edited Sep 12, 2013

...