Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Feb 2004
    Posts
    145
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Nested for loops and arrays

    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.

  • #2
    Regular Coder
    Join Date
    May 2002
    Location
    Virginia, USA
    Posts
    621
    Thanks
    0
    Thanked 6 Times in 6 Posts

  • #3
    Regular Coder
    Join Date
    May 2002
    Location
    Virginia, USA
    Posts
    621
    Thanks
    0
    Thanked 6 Times in 6 Posts
    given 2 arrays, $array1 and $array2....

    PHP Code:
    <?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)..
    Last edited by Celtboy; 02-25-2004 at 06:31 PM.

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hint: Use array_diff (http://de.php.net/array_diff).
    De gustibus non est disputandum.

  • #5
    Regular Coder
    Join Date
    May 2002
    Location
    Virginia, USA
    Posts
    621
    Thanks
    0
    Thanked 6 Times in 6 Posts
    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

  • #6
    Regular Coder
    Join Date
    Feb 2004
    Posts
    145
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thank you

    Cheers everyone, big help


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •