Jump to content

Merging Arrays And Removing Duplicate Values?


Silky1284

Recommended Posts

OK I'm almost finished with my code but I've run into the same problem. What I'm trying to do is perform the original function used to parse each ID in the array with each ID gathered from the function into an array without repeating the id if its already in the array. Basically appending to the current array without repeating the id if its already in the array.

 

Looking into array_push() or array_merge but not sure if that is the best way to go.

Currently it is repeating in what seems to be and endless loop of the same ids repeating.

 

Current Ouput: http://crowbarmafia.co.cc/spam/comments.php

Desired Output: Madea - 427789161, Anonymous - 513386222, SlLKY - 439573355, K i L L e R X - 505686564, Suicidal Silky - 512045047 within the table.

 

Here's an example of how the ids are set up...

 

Example:

$arrayid1= array(1, 2);

$arrayid2= array(2, 3);

$arrayid3= array(3, 4);

$arrayid4= array(4, 5);

 

Desired Output:

 

    [0.] => 1

    [1] => 2

    [2] => 3

    [3] => 4

    [4] => 5

 

 

 

 

$id = 513386222;

$sHost = "http://api.msappspace.com/proxy/relay.proxy?opensocial_authtype=SIGNED&opensocial_token=";
$sHost2 = "&opensocial_url=http%3A//mob-dynamic-lb1.mobsters06.com/mob/";

$header = file_get_contents($sHost.$myOSKey.$sHost2."get_comments%3Fuser_id%3D".$myID."%26target_id%3D".$id."%26session_id%3D".$mySESID."&nocache=1");
$commentEntery = split("<entry>", $header);

for($a=1; $a<count($commentEntery); $a++){
        $userID = split("<user_id>",$commentEntery[$a]);
        $userID = split("<", $userID[1]);
        $mob_name = split("<mob_name>",$commentEntery[$a]);
        $mob_name = split("<", $mob_name[1]);
        
        $mobnames[] = $mob_name[0];
        $ids[] = $userID[0];
}

$ids = array_unique($ids);
$mobnames = array_unique($mobnames);

foreach ($mobnames as $names){

         $name[] = $names;
                [list][/list]
}

foreach ($ids as $id){

        $uniqueIDs[] = $id;
       
}

for($m=0; $m<count($uniqueIDs); $m++){

$icomments = file_get_contents($sHost.$myOSKey.$sHost2."get_comments%3Fuser_id%3D".$myID."%26target_id%3D".$uniqueIDs[$m]."%26session_id%3D".$mySESID."&nocache=1");
$commentEntery = split("<entry>", $icomments);

for($a=1; $a<count($commentEntery); $a++){
        $userID = split("<user_id>",$commentEntery[$a]);
        $userID = split("<", $userID[1]);
        $mob_name = split("<mob_name>",$commentEntery[$a]);
        $mob_name = split("<", $mob_name[1]);
        
        $mobnames[] = $mob_name[0];
        $ids[] = $userID[0];
}

$ids = array_unique($ids);
$mobnames = array_unique($mobnames);

foreach ($ids as $id){

       //echo $id.'<br />';
       $uniqueIDs[] = $id;
       
}

foreach ($mobnames as $names){

        //echo $names.'<br />';
        $name[] = $names;
                
}
echo '<tr><td>'.$name[$m].'</td><td>'.$uniqueIDs[$m].'</td></tr>'."\n";	
}

?>

Link to comment
Share on other sites

i dont know if array key names can have spaces

like t his

$arr['abc eft'] = 12;// is t his valid?

 

 

if this is valid, u can do the following

put the name column as array keys

$arr[$table['name']]=$arr[$table['value']];

 

this will replace all same name with keys (keys can be different, but replaced with latest one)

 

 

based on your website's loading speed

users will leave it before it is done loading (i waited 5 minutes, and still loading!!!) (another iimportant is, browser is say 404 not found before u finish execute your entire script, if u used my method, or ur desired way, merge them, because most browser's default timeout is less than 60 seconds in most time, u cant change at server side, even if u changed, your server will be run out of resource if u got alot of users (like 100 per 10 minutes))

on my method

Link to comment
Share on other sites

Sorry I moved on and was editing the script. I tested what I wanted to do making a new script as an example... Basically I just want to add this to my current script! But the arrays are being created by my function which will loop through each array and end. Currently for each number it is creating a new array and making an endless loop.

 

<?php

$arrayid1= array(1, 2, 3, 4, 1, 2, 3, 4);
$arrayid2= array(2, 3, 4, 4, 1, 3);
$arrayid3= array(3, 4, 2, 2, 3);
$arrayid4= array(4, 5,);

$merge = array_merge($arrayid1, $arrayid2, $arrayid3, $arrayid4);

$arrayid = array_unique($merge);

foreach ($arrayid as $id){

       //echo $id.'<br />';
       $uniqueIDs[] = $id;
       	}

for($m=0; $m<count($uniqueIDs); $m++){
echo $uniqueIDs[$m].'<br />';
}

?>

Link to comment
Share on other sites

What are all the loops for? If you print_r($arrayid) you get your desired output (more or less, you can sort() it if you want to get sequential keys).

 

Well it only looping until its finished with each array ID.  What my script does is parses a set of ID's from each page.... then returns to the functions and parses the IDs from the next id in the array...  Simple terms it acts like a "Spider". It starts from one Id.. and branches out and parses the Ids from every id thereafter. and appends the ids to the array.. well that's what im attempting.

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.