note 68247 added to function.array-merge
| From: | sfletcher at abcoa dot com | Date: | Wed, 19 Jul 2006 16:28:29 +0000 |
| Subject: | note 68247 added to function.array-merge | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-114934@lists.php.net to get a copy of this message | ||
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...
----
Server IP: 64.71.164.2
Probable Submitter: 64.31.141.2
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.array-merge.php
Edit -- http://master.php.net/note/edit/68247
Del: integrated -- http://master.php.net/note/delete/68247/integrated
Del: useless -- http://master.php.net/note/delete/68247/useless
Del: bad code -- http://master.php.net/note/delete/68247/bad+code
Del: spam -- http://master.php.net/note/delete/68247/spam
Del: non-english -- http://master.php.net/note/delete/68247/non-english
Del: in docs -- http://master.php.net/note/delete/68247/in+docs
Del: other reasons-- http://master.php.net/note/delete/68247
Reject -- http://master.php.net/note/reject/68247
Search -- http://master.php.net/manage/user-notes.php