Ankündigung

Einklappen
Keine Ankündigung bisher.

Tupel aus einem Array mit foreach rausholen?

Einklappen

Neue Werbung 2019

Einklappen
X
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • #16
    hatte ich auch schon gedacht, aber da kommt nur murks raus

    Code:
                <UndirectedRelation  fromID="Array" toID="Array" lineSize="1"/>
                <UndirectedRelation  fromID="Array" toID="Array" lineSize="1"/>
                <UndirectedRelation  fromID="Array" toID="" lineSize="1"/>
                <UndirectedRelation  fromID="Array" toID="Array" lineSize="1"/>
                <UndirectedRelation  fromID="Array" toID="Array" lineSize="1"/>
                <UndirectedRelation  fromID="Array" toID="" lineSize="1"/>
                <UndirectedRelation  fromID="Array" toID="" lineSize="1"/>
                <UndirectedRelation  fromID="Array" toID="" lineSize="1"/>
                <UndirectedRelation  fromID="Array" toID="" lineSize="1"/>
                <UndirectedRelation  fromID="Array" toID="" lineSize="1"/>
                <UndirectedRelation  fromID="Array" toID="" lineSize="1"/>
                <UndirectedRelation  fromID="Array" toID="" lineSize="1"/>
                <UndirectedRelation  fromID="Array" toID="" lineSize="3"/>
                <UndirectedRelation  fromID="Array" toID="" lineSize="3"/>
                <UndirectedRelation  fromID="Array" toID="" lineSize="2"/>
    aber wenn das foreach array_pop() lässt und das $items = array(); richtig positioniert, dann geht es!
    Dankeschön!!!!!!
    echt, vielen vielen dank!!!!!
    Ich war schon am verzweifeln!
    Hier findet Ihr alles, was ich dank eurer Hilfe geschafft habe und noch mehr: http://viskoda.viktor-dite.de

    Kommentar


    • #17
      Ach ja, klar:
      PHP-Code:
      foreach($items as $ivalue){
          
      $xmlrelation.='<UndirectedRelation  fromID="'.$ivalue[0].'" toID="'.$ivalue[1].'" lineSize="'.$count.'"/>';

      [COLOR="#F5F5FF"]--[/COLOR]
      [COLOR="Gray"][SIZE="6"][FONT="Georgia"][B]^^ O.O[/B][/FONT] [/SIZE]
      „Emoticons machen einen Beitrag etwas freundlicher. Deine wirken zwar fachlich richtig sein, aber meist ziemlich uninteressant.
      [URL="http://www.php.de/javascript-ajax-und-mehr/107400-draggable-sorttable-setattribute.html#post788799"][B]Wenn man nur Text sieht, haben viele junge Entwickler keine interesse, diese stumpfen Texte zu lesen.“[/B][/URL][/COLOR]
      [COLOR="#F5F5FF"]
      --[/COLOR]

      Kommentar


      • #18
        So, hab es jetzt soweit fertig, vielen vielen Dank nochmal!!!!

        hier ist der Quellcode, falls es jm. interessiert


        Code:
        <?php
        
        $wgExtensionFunctions[] = 'showRel';
        
        
        /**
         * @make a new tag <relations/>
         */
        function showRel() {
                global $wgParser;
                $wgParser->setHook( "relations", "mainRel" );
                return true;
        }
        
        
        function mainRel($text, $params, &$parser) {
          global $wgOut;
          global $wgTitle;
          
          $cap = new Relations();
          $cap->doRelationsQuery();
          
          $graph=$cap->makeGraph($cap->my_counter($cap->maketupel($cap->users)));
          
          $output = $parser->recursiveTagParse('<graphviz renderer="neato">'.$graph.'</graphviz>');
          return $output;
          
        	
        }
          
        class Relations{
        var $users = Array();
        var $ucount = Array();
        var $debug=false;
        
        
        function debugOut($input){
        	echo '<pre>';
        	print_r( $input);
        	echo '</pre>';
        }
        
        
        //GraphViz Dataset 
        function makeGraph($input){
        	global $wgOut;
        	$graphnode='';
        	$graphrelation='';
        	$graph = 'graph g{ overlap=scale; splines=true; node [height=0 style="filled", shape="ellipse", color="lightblue"];
        	';
        	foreach($input as $value){
        		if(count($value)==3){ //Falls Tupel nicht eine einzelne Person ist
        			$count=$value['count'];
        			unset($value['count']);
        			
        			$one=array_pop($value);
        			$two=array_pop($value);
        			$graphrelation.=$one.' -- '.$two.' [style="setlinewidth('.$count.')"];
        			';
        			
        		}
        	}
        	$graph.=$graphnode.$graphrelation.'}';
        	if($this->debug) $this->debugOut($graph);
        	return $graph;
        }
        
        
        
        function doRelationsQuery() {
        
        	$dbr =& wfGetDB( DB_SLAVE );
        	$res = $dbr->query('SELECT distinct rev_user, rev_user_text, rev_page FROM revision WHERE rev_minor_edit=0 AND NOT rev_user=0 order by rev_page');
        	
        	while($obj = $dbr->fetchObject($res)){
        	
        		$this->users[$obj->rev_page][$obj->rev_user]=$obj->rev_user_text;
        	}	
        	if ($cap->debug) $cap->debugOut($cap->users);	
        	
        } 
        
        function maketupel($input)
        {
          $output = array();
          foreach($input as $key => $value) //nur das value
          {
          	/* Wenn das Array ein nTupel ist, muss es zu einem 
          	 * 2er Tupel aufgebrochen werden */
          	if(count($value)>2){
          		$items = array ();
        		
        		
        		/*
        	 	 ****************************************************************
        	 	 * Jedes mit jedem als Tupel
        	 	 * Dieses Codefragment ist mit Hilfe des php.de Forums entstanden
        	 	 * Mein besonderer Dank an nikosch!
        	 	 */
        		while (true)
        		{
        			$item = array_shift($value);
        			if (empty ($value)) break;
        			$items = array_merge ($items , array_map (null , $value, array_fill (0 , count ($value) , $item)));
        		}
        		/*
        		 *****************************************************************
        		 */
        		 
        		/*Die Tupelelemente einzeln zum neuen Array zusammenfügen*/
        		foreach($items as $ivalue){
        			array_push($output,$ivalue);
        		}
          	}
          	else array_push($output,$value);
          }
          if ($this->debug) $this->debugOut($output);
          return $output;
        }
        
        /* 
         * **************************************************************
         * Fuer die naechsten beiden Funktionen moechte ich 
         * dem http://www.php.de Forum sehr danken!
         * Mein besonderer Dank an nikosch!
         */
         
        function my_unique($input)
        {
          $output = array();
          foreach($input as $key => $value)
          {
            if(!in_array($value,$output))
              $output[$key] = $input[$key];
          }
          if ($this->debug) $this->debugOut($output);
          return $output;
        }
        
        function my_counter($input)
        { // funktioniert nur mit mehrdimensionalen arrays
          $elements = $this->my_unique($input);
          foreach($elements as $key => $value)
          {
            $elements[$key]["count"] = count(array_keys($input,$value));
          }
          if ($this->debug)$this->debugOut($elements);
          return $elements;
        }
        
        /* 
         * ***************************************************************
         */
        } 
        ?>
        Hier ist eine detaillierte Beschreibung
        Hier findet Ihr alles, was ich dank eurer Hilfe geschafft habe und noch mehr: http://viskoda.viktor-dite.de

        Kommentar

        Lädt...
        X