答案 0 :(得分:2)
使用name
中的array
在select
选项上使用它
<?php
$arr = array (
array (
'slug' => 'acura',
'name' => 'Acura',
'name_en' => 'Acura',
),
array (
'slug' => 'alfa-romeo',
'name' => 'Alfa Romeo',
'name_en' => 'Alfa Romeo',
),
array (
'slug' => 'alpine',
'name' => 'Alpine',
'name_en' => 'Alpine',
),
array (
'slug' => 'aro',
'name' => 'ARO',
'name_en' => 'ARO',
),
array (
'slug' => 'aston-martin',
'name' => 'Aston Martin',
'name_en' => 'Aston Martin',
),
);
?>
<select name="names">
<option value="">Select</option>
<?php
foreach($arr as $key => $value):
echo '<option value="'.$key.'">'.$value['name'].'</option>';
endforeach;
?>
</select>
答案 1 :(得分:1)
$response = array (
0 =>
array (
'slug' => 'acura',
'name' => 'Acura',
'name_en' => 'Acura',
),
1 =>
array (
'slug' => 'alfa-romeo',
'name' => 'Alfa Romeo',
'name_en' => 'Alfa Romeo',
),
2 =>
array (
'slug' => 'alpine',
'name' => 'Alpine',
'name_en' => 'Alpine',
),
3 =>
array (
'slug' => 'aro',
'name' => 'ARO',
'name_en' => 'ARO',
),
4 =>
array (
'slug' => 'aston-martin',
'name' => 'Aston Martin',
'name_en' => 'Aston Martin',
)
);
echo "<select>";
foreach($response as $option){
echo "<options value='".$option['name_en']."'>".$option['name_en']."</options>";
}
echo "</select>";
答案 2 :(得分:0)
您可以尝试以下代码:
<?php
$list = array (
0 =>
array (
'slug' => 'acura',
'name' => 'Acura',
'name_en' => 'Acura',
),
1 =>
array (
'slug' => 'alfa-romeo',
'name' => 'Alfa Romeo',
'name_en' => 'Alfa Romeo',
),
2 =>
array (
'slug' => 'alpine',
'name' => 'Alpine',
'name_en' => 'Alpine',
));
?>
<html>
<head> </head>
<body>
<select>
<?php foreach ($list as $lv){ ?>
<option><?= $lv['name'] ?></option>
<?php } ?>
</select>
</body>
</html>
如果您要更改它,我已经列出了name
,然后使用另一个索引slug
或name_en