Jump to content

attaching a name to a number - (i.e., help)


glennn.php

Recommended Posts

ok, i checkboxes whose values might be any array of integers (1, 6, 14)...

 

with "1" meaning "Dog", 6 meaning "Elephant", "14" meaning "Wife", etc., i need to echo a name for each selected checkbox (i cannot change the values of them)...

 

having this:

 

for($x=0; $x<count($category); $x++)
{
        $exp= $category[$x];
                   
         echo $exp[0] . '<br />';  // output each selected category
}

 

could someone show me how i might convert the "1" to "Dog", etc...?

 

thanks much,

GN

Link to comment
https://forums.phpfreaks.com/topic/104279-attaching-a-name-to-a-number-ie-help/
Share on other sites



Array ( [0] => 3-Cardiovascular Pathology [1] => 4-Cytopathology [2] => 7-Gastrointestinal Pathology [3] => 9-Gynecological Pathology ) 



 

i have to take the "-Cardiovascular Pathology" out of the db inserts and just use ints...

Okay, so take the names of the categories OUT of the checkboxes and use this:

 

$checkboxlist = array(1=>"Dog", "Giraffe", "Cow", "Pig", "Farmer", "Elephant" .... "Wife");

 

foreach ($_POST['category'] as $k=>$v) {

  echo $checkboxlist[$v];

}

 

I used the wrong variable last time.  Remember, take the other part out and just leave the number.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.