let's say I have an array( 1=>something, 2=>else, 3=>entirely)

I want to use the foreach element in the array, return the other elements in the array..

so 1 will return 2 and 3, 2 will return 1 and 3, and 3 will return 1 and 2... this array may contain two to dozens of elements at a given time

how do i do this?

    care to explain that some other way, makes no sense to me

      foreach element in the array I want to retrieve the other elements in the array.. basically im building a relationship between them in the database...

      so lets say i have a form with a list of usernames.. you can check multiple users and submit to 'form a 'relationship' or 'family' if you will ...

      so lets say the form returns an array like so : array(1=>David, 2=>Mike, 3=>Carol)

      so for David i want to insert Mike and Carol into his 'family' column in the database...

      for Mike i want to insert Carol and David... etc

      but i dont want to insert themselves into their own 'family' field...

        inside the foreach loop check the array key against the id i assume you have some how,if its a match don't do what ever, other wise do do what ever.

          fontener;10972928 wrote:

          what id? ..still confused 😕

          i'm more confused, how about some code.
          id=which array key you want to exclude

            $array = array(1=>Mike, 2=>David, 3=>Carol);

            foreach ($array as $key => $value){

            insert $array[keys] where $array[key] !=$key <--- *NOT ACTUAL CODE but the general idea of what im looking for

            }

              $array = array(1=>Mike, 2=>David, 3=>Carol);
              
              foreach ($array as $key => $value){
              
              if($key !=?????????????){
              //do what ever
              {
              
              }

              how are you defining what to exclude?

                im probably making this harder than it should be.. maybe it's the late hours..

                foreach($array as $key => $value)

                insert {all elements of array} into {users table} {family column} EXCEPT {array element that is equal to $value

                  <?php
                  
                  $a = array(1=>David, 2=>Chris, 3=>Nina);
                  
                  function mycallback($input_var_inner) { 
                      global $var_to_pass; 
                      return ($input_var_inner!=$var_to_pass) ? true : false; 
                      }
                  
                  function myfilter($input_var_outer,$param) { 
                  
                  global $var_to_pass; 
                  $var_to_pass = $param; 
                  
                  $return_arr = array_filter($input_var_outer,'mycallback'); 
                  //re-key if you want 
                  //$return_arr = array_merge(array(),$return_arr); 
                  return $return_arr; 
                  
                  } 
                  foreach($a as $key=>$value){
                  $exclude = $value; 
                  
                  //remove elements from array that are equal to current_value 
                  $b = myfilter($a,$exclude); 
                  
                  echo "<pre>"; 
                  print_r($b); 
                  echo "</pre>"; 
                  }
                  ?> 
                    Write a Reply...