vreesh Posted October 24, 2008 Share Posted October 24, 2008 hi all, i'm poring about 2 days over it, but i can't get an sollution I would like to filter pair edges like <fromID=2 toID=6> <fromID=6 toID=9> <...> <fromID=9 toID=1> from an dynamicly growing and shrinking Array like Array ( [2]=>Inkognito [6]=>TheKing [9]=>Vister [...]=> ... [1]=>Dummy [count]=>3 //is always there ) the $keys are UserIDs, they are not ordered and not ever complete! the $values are the Usernames which i have to use for defining nodes like <Person id=$key name=$value> the last one i do with foreach($array as $key=>$value){ if ($ikey!=="count"){ $xmlnode .= '<Person id="'.$key.'" name="'.$value.'"/>'; } } but i'm not sure how to get the pairs edges Link to comment https://forums.phpfreaks.com/topic/129928-how-to-filter-pairs-from-an-array/ Share on other sites More sharing options...
feidakila Posted October 24, 2008 Share Posted October 24, 2008 what is the logic of that pairs edges? Link to comment https://forums.phpfreaks.com/topic/129928-how-to-filter-pairs-from-an-array/#findComment-673561 Share on other sites More sharing options...
vreesh Posted October 24, 2008 Author Share Posted October 24, 2008 the logic is for building a graph. //Nodes <Person id=2 name=Inkognito> <Person id=6 name=TheKing> <...> <Person id=9 name=Vister> //Edges <Edge fromID=2 toID=6> <Edge fromID=6 toID=9> <...> <Edge fromID=9 toID=1> Link to comment https://forums.phpfreaks.com/topic/129928-how-to-filter-pairs-from-an-array/#findComment-673567 Share on other sites More sharing options...
feidakila Posted October 24, 2008 Share Posted October 24, 2008 I mean, how do you obtain the edges?? are they fixed value edges?? 2-6, 6-9 Sorry but I don't understand how do you obtain the edges ??? Link to comment https://forums.phpfreaks.com/topic/129928-how-to-filter-pairs-from-an-array/#findComment-673571 Share on other sites More sharing options...
vreesh Posted October 24, 2008 Author Share Posted October 24, 2008 this array is the second from a two dimensional array. all entries inside this array are nodes which have to be connected. i cant do it in a for loop (key[$i] and key[$i+1]) because the keys are not out of (1...n) continuosly. Link to comment https://forums.phpfreaks.com/topic/129928-how-to-filter-pairs-from-an-array/#findComment-673649 Share on other sites More sharing options...
sasa Posted October 24, 2008 Share Posted October 24, 2008 try <?php $test = Array ( 2=>'Inkognito', 6=>'TheKing', 9=>'Vister', 5=>'sasa', 1=>'Dummy', 'count'=>3 //is always there ); $edge = $test; unset($edge['count']); $edge = array_keys($edge); for ($i = 1; $i < count($edge); $i++){ $out .= "<fromID=".$edge[$i-1]." toID=".$edge[$i].">\n"; } echo $out; ?> Link to comment https://forums.phpfreaks.com/topic/129928-how-to-filter-pairs-from-an-array/#findComment-673816 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.