php how to get values from a var problem?
I have a small PHP script that takes the values from a dropdo开发者_开发技巧wn 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?
Ok so do:
$defences_results = $game_set->get_my_defences();
foreach( $defences_results as $key => $value){
print '<li>'.$options[$value['stake']].' </li>';
}
精彩评论