Web Analytics Made Easy -
StatCounter Nested for loops and arrays - CodingForum

Announcement

Collapse
No announcement yet.

Nested for loops and arrays

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new 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
    try this: http://www.php.net/manual/en/function.array-merge.php

    Comment


    • #3
      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; Feb 25, 2004, 12:31 PM.

      Comment


      • #4
        Hint: Use array_diff (http://de.php.net/array_diff).
        De gustibus non est disputandum.

        Comment


        • #5
          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

          Comment


          • #6
            Thank you

            Cheers everyone, big help

            Comment

            Working...
            X