...

View Full Version : Nested for loops and arrays



heaps21
02-25-2004, 04:41 PM
Hi, I have 2 arrays of usernames and I want to create a new array containing usernames that are in array1 that arent in array2. It sounds simple in theory but i just cant figure out the logic of how to do it (although I was thinking along the lines of nested for loops). Can any one help?
Cheers.

Celtboy
02-25-2004, 05:20 PM
try this: http://www.php.net/manual/en/function.array-merge.php

Celtboy
02-25-2004, 05:29 PM
given 2 arrays, $array1 and $array2....



<?php


function get_unique($username) {

gobal array2;
foreach ($array2 as $value) {
if ($username == $value) {
return();
}
}

return($username);

}


$new_array = array_filter($array1,"get_unique");

(that *SHOULD* work... ;-P)..

mordred
02-25-2004, 06:20 PM
Hint: Use array_diff (http://de.php.net/array_diff).

Celtboy
02-25-2004, 06:52 PM
DUH...that's SOOOO what I meant to put....er......bloody. I even looked at the stupid function when recalling the array_filter() parameters....stinko...

;)

gj.

-Celt

heaps21
02-25-2004, 08:18 PM
Cheers everyone, big help :D



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum