Jump to content

how to filter pairs from an array?


vreesh

Recommended Posts

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

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;
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.