Jump to content


array unset bug

  • Please log in to reply
No replies to this topic

#1 Tjk

  • Members
  • PipPip
  • Member
  • 27 posts

Posted 31 May 2006 - 08:23 PM

In the script below what I am trying to do is to create a counter whereby it takes a random variable from the arrays $stats adds it's value (taken from a mysql table and stored in a variable) to a string and then unsets the element so that on the next loop it will not show the value again. But when i try it, it displays more than one of the same element and i'm not sure why. I know it's a simple problem but could anyone point me in the right direction.

    $numElements = count($stats);
    $numElements += "1";
    $ss= "0";
    $stats= array("command", "power", "agility", "knowledge", "acumen", "charisma");
    for($i; $i < $numElements; $i++){    
      $dispstats= array_rand($stats);
      $disp= $stats[$dispstats];
      if($disp == "command"){
        $dispfriend= $dispfriend. "-Command: ".$sfcomm."-";
      else if($disp == "power"){
        $dispfriend= $dispfriend. "-Power: ".$sfpow."-";
      else if($disp == "agility"){
        $dispfriend= $dispfriend. "-Agility: ".$sfagil."-";
      else if($disp == "knowledge"){
        $dispfriend= $dispfriend. "-Knowledge: ".$sfknow."-";
      else if($disp == "acumen"){
        $dispfriend= $dispfriend. "-Acumen: ".$sffacu."-";
      else if($disp == "charisma"){
        $dispfriend= $dispfriend. "-Charisma: ".$sfchar."-";
      if($ss == $statview){

Help appreciated as always

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users