Patrioticcow
Patrioticcow

Reputation: 27038

php how to get values from a var problem?

I have a small PHP script that takes the values from a dropdown list and attaches some other strings to them:

$options = array(
    '1' => 'Backgammon',
    '2' => 'Chess',
);
$value = $_POST['gamelist'];
echo $options[$value];

What if I want to grab the values from a variable instead of a dropdown list? How do I do that? My var is:

$defences_results = $game_set->get_my_defences();
foreach( $defences_results as $key => $value) {
    print '<li>'.$value['stake'].' </li>
}

The print displays 1, 2, etc. I want to replace that with: Backgammon, Chess, etc. What I was doing is using .$options[$value].

Any ideas?

Upvotes: 1

Views: 245

Answers (1)

Naftali
Naftali

Reputation: 146310

Ok so do:

$defences_results = $game_set->get_my_defences();
foreach( $defences_results as $key => $value){
   print '<li>'.$options[$value['stake']].' </li>';
}

Upvotes: 2

Related Questions