i have some perl code which i want to get working in a php script. what do i need to change in the following code to get it work in php (i already changed elsif to elseif and the position of rand but it still did not work)

original perl

if($sum[1]<15){$fact2a ="v";}
elseif($sum[1]>15){$fact2a ="c";}
else { $fact2a = ("c", "v")[rand 2]; }

current php which does not work

if($sum[1]<15){$fact2a ="v";}
elseif($sum[1]>15){$fact2a ="c";}
else { $fact2a =rand ("c", "v"); }

it's the rand function that's not working, the first two lines work.

    not ENTIRELY sure what you're going for...but...

    if ( $sum[1] < 15)
    {
      $fact2a ="v";
    }
    
    elseif ( $sum[1] > 15)
    {
      $fact2a ="c";
    }
    
    else
    {
      $fact2a = chr(rand(ord("c"), ord("v"));
    }
    

    Maybe that helps?

      the above code picks randomly between j-p, i.e. jklmnop. i only want j or p to be selected.

        Ooooh! Well that certainly changes things a bit (though...it does between C and V...). You can create a small array with two items for the else {} section:

        
        else
        {
           $chars = array ( "c", "v" );
        
           $fact2a = $chars[rand(0,1)];
        }
        
        

        This a little bit closer?

          Write a Reply...