• Welcome to Overclockers Forums! Join us to reply in threads, receive reduced ads, and to customize your site experience!

PHP Array help...

Overclockers is supported by our readers. When you click a link to make a purchase, we may earn a commission. Learn More.

Archer36

Member
Joined
Jun 18, 2004
Location
Michigan, US
Well im a bit lost and looking for help so lets see what you guys got for me.

I am making a PHP script that takes kismet .CSV files and combines them, I have that part working fine however the part I am having trouble with is removing the duplicate lines.

I am using the
PHP:
file
function to take the .csv file and put each line into a array. Now I want to search the whole array for duplicate MAC address, when it finds one it deletes one of the lines containg the MAC.

As far as I can tell, the file function takes each line and goes "0 => info from line one, 1 => info from line two, 2 => info rom line three..."

So does anyone know how to search that array? I have tried
PHP:
array_search
however it returns the first key then stops, as far as I know there is no way to get it to list ALL of the matching.
 
hmm, how bout this.


Code:
foreach($array as $macaddress) 
{//start looping through the array, grabbing the mac address to check for.
 $found_match=FALSE; //set the found match for this specific mac address to false;
 foreach($array as $key=>$value)
 {//loop through the array again, this time to grab the key and value, in order to compare against the mac address previously grabbed

  if($macaddress==$value and $found_match==FALSE)
  { //the mac addresses match, and no match has been found previously
    $found_match=TRUE; //now a match has been found!
  }
  elseif($macaddress==$value and $found_match==TRUE)
  {// the mac addresses match, but a match has been found 
    unset($array[$key]); //delete extra match
  }
 }//end the as $key=>$value loop, start again on with the next row in the array
}//whew... array cleaned!
 
Last edited:
so I can specify array_uniqe to look for unique MAC addys only? But how do I return the whole line not must the MAC address?
 
use $array = array_unique($array);

and then your array will be stripped of all duplicate entrys.

Then you can just retrieve each line with a foreach loop. Tada!
 
Back