3 Replies Latest reply on Dec 13, 2010 4:38 PM by Fayena

    difference in array behavior between php and flex?

    Fayena

      I think this problem is probably caused by a difference in array behavior between php and flex that I'm not quite grasping.  This is the flex code that I have written and the php code is posted below it.  I'm new to flex and this really has me stumped.    Thanks much for your help.   

       

      Inputs are sire=[SB1,kit] dam=[kit,kit] sireLinkedP=[E,P],[e,P]

      Output should be (and is with PHP) random=[E,P,SB1],[E,P,kit],[e,P,SB1],[e,P,kit]

      What I'm getting is random=[E,P,SB1,kit],[E,P,SB1,kit],[e,P,SB1,kit],[e,P,SB1,kit] 

       

      function randomlinks(sire:Array,dam:Array,sireLinkedP:Array):Array{

      var str:String = sire[0].toUpperCase();

      var str1:String = sire[1].toUpperCase();

      var str2:String = dam[0].toUpperCase();

      var str3:String = dam[1].toUpperCase();

      var x:uint = sireLinkedP.length;

      var k:uint = 0;

      var random:Array = new Array();

      x--;

      trace("randomlinks sirelinked:" + sireLinkedP);

       

      for (var i:uint = 0;i<=x;i++){    

            for (var j:uint = 0;j<=1;j++){

                random[k]= sireLinkedP[i];

                trace("random" + k + ":" + random[k]);

           if (str==sire[0]|| str1==sire[1]|| str2==dam[0] || str3==dam[1]) {

                random[k].push(sire[j]);

           }//end if

           trace("random" + k + ":" + random[k]);

           k++;

           }//end for loop

        

      }//end for loop

      trace("randomlinks:" + random);

      return(random);

      }//end function randomlinks

       

       

      function randomlinks($sire,$dam,$sirelinked){

      $x=count($sirelinked);

       

      $x--;

      $k=0;

       

      for ($i=0;$i<=$x;$i++){    

          for ($j=0;$j<=1;$j++){

              $random[$k]=$sirelinked[$i];

      if  (ctype_upper($sire[0]) || ctype_upper($sire[1]) || ctype_upper($dam[0]) || ctype_upper($dam[1])){

      array_push($random[$k],$sire[$j]);}

              $k++;

          }

       

      }

      return($random);

      }