I need help to replace MySQL values with array values, something like this:

$mysqlcolor = $myrow[color];

$colors=array('
Green,
Red,
Brown,
Grey,
Blue
');

If $mysqlcolor is "0" I need to replace this with the first value in array = "Green". If $mysqlcolor is "3" I need to replace it with third value in array = "Grey", etc, etc.

$newcolor=$arrayvalue;

echo "$newcolor";

Thanks for help.

    Just use the number assigned to the $mysqlcolor variable as the index in the $newcolor definition:

    $newcolor = $colors[$mysqlcolor];
    

      Thanks, TheDefender, I tried this, but it didnt work. Now I changed to:

      $colors=array(
      "Green",
      "Red",
      "Brown",
      "Grey",
      "Blue"
      ');

      and works great.

        Hey sorry... I didn't even notice the syntax error in your array to begin with. Glad you got it working. Have a night day!

          Write a Reply...