Click to See Complete Forum and Search --> : flatten heirarchy/ unique subgoup elements


Lucky-8
August 12th, 2008, 11:00 AM
Hello,
I have implemented a datastructure which has a user id and a flag in its member variable and a member which returns true if the users contact list has already been generated. My first aim is to get all the users and their user ids nicely structured into one array, simply flatten the heirarchy without any duplicate entries i.e starting from one root user generate his contact list, then generate contact lists of all the entries in the root users contacts, so on to 3 levels.... once i have this done then i can form the graph between users who are related to each other...
my code is below


<?php
class contact_user
{
var $flag;
var $nsid;
var $obj_array=array();
//constructor which initialises user's id and sets his contact generated flag to false
function __construct($id)
{
$flag=false;
$nsid=$id;
}
//Function which checks if users contacts have already been generated
function check_user_flag($array)
{
for($i=0;$i<sizeof($array);$i++)
{

$obj=$array[$i];
if($obj->nsid==$this->nsid)
{
return true;
}
}
return false;
}
}//end of class contact_user

?>
<?php


require_once("phpFlickr.php");
//creating an object of phpFlickr with the key as an argument
$f = new phpFlickr("555013b682d0a671e42aba02d3be989d");

$status_flag=false;
$ini_val="28890953@N07";
$obj = new contact_user($val);
$contact = $f->contacts_getPublicList($ini_val);


foreach($contact['contact'] as $newarray)
{
//assigning the flag to true for the user who has been already checked
$obj->flag=true;
$obj_array[]=$obj;

$array_nsid[$ini_val][]=$newarray['nsid'];
$array_username[$ini_val][]=$newarray['username'];

$value=$newarray['nsid'];
$obj= new contact_user($value);
$result=$obj->check_user_flag($obj_array);
if($result)
{
$status_flag=false;
$contact_level2 = $f->contacts_getPublicList($value);

foreach($contact_level2['contact'] as $newarray2)
{
$obj->flag=true;
$obj_array[]=$obj;

$array_nsid[$value][]=$newarray2['nsid'];
$array_username[$value][]=$newarray2['username'];

$value2=$newarray2['nsid'];
$obj=new contact_user($value2);
$result2=$obj->check_user_flag($obj_array);

if($result2)
{


$contact_level3 = $f->contacts_getPublicList($value2);

foreach($contact_level3['contact'] as $newarray3)
{
$obj->flag=true;
$obj_array[]=$obj;

$array_nsid[$value2][]=$newarray3['nsid'];
$array_username[$value2][]=$newarray3['username'];
}//end of inner foreach
}//end of inner if
}//end of outer foreach

}//end of first if
}//end of main foreach
echo "<pre>";
print_r($array_nsid);
echo "</pre>";
echo "<pre>";
print_r($array_username);
echo "</pre>";
echo "</td></td></table>";
?>



Below the result


Array
(
[28890953@N07] => Array
(
[0] => 99339743@N00
[1] => 7104922@N05
)

)

Array
(
[28890953@N07] => Array
(
[0] => gvendurjaki
[1] => Oded Nov
)

)


I guess this is an issue of how php treats instances espescially the this pointer..... please help!!