Jump to content

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

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.