我正在寻找一种创建方式
<option>.Name1.</option>
<option>.OtherName.</option>
对于每个最高值,请继续考虑如何提取数组值,而不知道名称(Name1,OtherName等,这些值将动态变化)。对于print_r或var_dump,您将看到以下结构:
array (
'Name1' =>
array (
'diametru' =>
array (
0 => 15,
7 => 16,
),
'latime' =>
array (
0 => 6,
9 => 5,
),
),
'OtherName' =>
array (
'diametru' =>
array (
0 => 16,
2 => 17
),
'latime' =>
array (
0 => 6,
1 => 7,
10 => 5,
35 => 8,
),
),
.........
)
感谢您能提供的任何帮助。
答案 0 :(得分:2)
您可以只使用Foearch:
<select>
<?php
foreach($array as $keyname=> $list)
{
echo '<option value="'.$keyname.'">'.$keyname.'</option>';
}
?>
</select>
答案 1 :(得分:2)
您有很多方法可以做到:
$var = [
'Name1' => [
'diametru' => [
0 => 15,
7 => 16,
],
'latime' => [
0 => 6,
9 => 5,
],
],
'OtherName' => [
'diametru' => [
0 => 16,
2 => 17
],
'latime' => [
0 => 6,
1 => 7,
10 => 5,
35 => 8,
],
]
];
foreach ($var as $index => $value) {
echo "<option>$index</option>";
}
foreach (array_keys($var) as $index) {
echo "<option>$index</option>";
}
答案 2 :(得分:0)
$array = [
'Name1' => [
'diametru' => [7,6]
],
'othername' => []
];
$output = array_keys($array);
$option = '';
foreach ($output as $val) {
$option .= "<option>$val</option>";
}
print_r($option);