note 68247 deleted from function.array-merge by levim
| From: | levim@php.net | Date: | Mon, 24 Feb 2014 22:55:12 +0000 |
| Subject: | note 68247 deleted from function.array-merge by levim | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-198683@lists.php.net to get a copy of this message | ||
Note Submitter: sfletcher at abcoa dot com
----
I found that array_merge() didn't work in my case as it should have because I still get
duplicate values. Again, I noticed that the values can be overwritten if the array's key are
the same as stated in the manual.
So, I came up with the alternative and it work like a charm.
--snip--
function array_merge_alternative1() {
//echo func_num_args(); /* Get the total # of arguements (parameter) that was passed to this
function... */
//print_r(func_get_arg()); /* Get the value that was passed in via arguement/parameter #...
in int, double, etc... (I think)... */
//print_r(func_get_args()); /* Get the value that was passed in via arguement/parameter #...
in arrays (I think)... */
$loop_count1 = func_num_args();
$junk_array1 = func_get_args();
$xyz = 0;
for($x=0;$x<$loop_count1;$x++) {
$array_count1 = count($junk_array1[$x]);
if ($array_count1 != 0) {
for($y=0;$y<$array_count1;$y++) {
$new_array1[$xyz] = $junk_array1[$x][$y];
$xyz++;
}
}
}
$new_array2 = array_unique($new_array1); /* Work a lot like DISTINCT() in SQL... */
return $new_array2;
}
--snip--
Cheer...