Jump to content

searching for "a needle in a haystack"


Archimedees

Recommended Posts

 

I have two arrays,  $arCurrentHost and $arCurrentServer they both contains list of servers.

Now, some values inthe first array are also in the second array. I want to create a third array containing values in both lists.

First, I assign the keys in the second array to a $needle and walk through the first array to see if there is a hit. If hit, we do nothing,

if no hit, we add the needle to $arCurrentHost. Can somebody please pinpoint why this function is not returning the results I want?

Please? Thanks.

 

function create_list($arNewCurrentHost)

{

  if (isset($arCurrentHost) && (isset($arCurrentServer))

  {

  $arNewCurrentHost = $arCurrentHost;

  $i=0;

  $MaxCurrentServer = count($arCurrentServer);

    for($i=0;  $i<$MaxCurrentServer; $i++)

    {

    $needle = $arCurrentServer [$i];

    }

    array_search($arNewCurrentHost, $needle);

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

    {

    if($value == $needle)

    {

      //do nothing

    }

    else

    {

    array_push($arNewCurrentHost, $needle );

    }

   

    }

  }

  else

  {

  die();

  } 

return $arNewCurrentHost;

 

}

 

Link to comment
Share on other sites

 

array_intersect gives an array containing elements in first array that are also in second array, leaving out the elements in first array that are not in second array and vice-versa. I want to have an array containing all the elements in first and all the elements in second array. If the elements in second array already exist in first array we just do nothing but if not we add them to the first array. Thanks.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.