This is my php array $data.
这是我的php数组$ data。
Array
(
[upcoming] => Array
(
[webinars] => Array
(
[0] => Array
(
[webinarKey] => 123456
[subject] => webinar title ...
[times] => Array
(
[0] => Array
(
[startTime] => 2014-04-03T00:00:00Z
Please check my code below. I want to get values of "webinarkey" and "subject" and "start date - with date formatted" and put them into my select box. I can now populate "webinarkey and "subject". Thank you all to help to to populate "webinarkey and subject" but now i want to show "start date with date format as well.
请检查下面的代码。我想得到“webinarkey”和“subject”以及“开始日期 - 日期格式化”的值,并将它们放入我的选择框中。我现在可以填充“webinarkey和”主题“。谢谢大家帮忙填写”webinarkey和subject“,但现在我想显示”日期格式的开始日期“。
echo '<form method="POST"><select>';
foreach ($data["upcoming"]["webinars"] as $webinar) {
echo '<option value="' . htmlspecialchars($webinar["webinarKey"]) . '">' . htmlspecialchars($webinar["subject"]) . htmlspecialchars($webinar["times"]["startTime"]) . '</option>';
}
echo '</select></form>';
Please help me to show start date as well.
请帮我看一下开始日期。
3 个解决方案
#1
1
$data = array(/**/);
foreach ($data["upcoming"]["webinars"] as $webinar) {
echo '<option value="' . htmlspecialchars($webinar["webinarKey"]) . '">' . htmlspecialchars($webinar["subject"]) . '</option>';
}
From what I gather the only array you need to loop over is $data["upcoming"]["webinars"]
.
从我收集的内容中,您需要循环的唯一数组是$ data [“coming”] [“webinars”]。
Ensure your output HTML is valid and your data is escaped properly.
确保输出HTML有效,并且您的数据已正确转义。
#2
0
Since you are trying to access a value in a multidimensional array, you cannot use ->
as that is for properties of objects. Instead you need to access it like a normal array: $array[key]
由于您尝试访问多维数组中的值,因此不能使用 - >,因为它适用于对象的属性。相反,你需要像普通数组一样访问它:$ array [key]
Updated Code:
更新的代码:
echo '<select>';
foreach ($webinars as $obj)
{
foreach ($obj['webinars'] as $ob)
{
echo '<option value='.$ob['webinarKey'].'>'.$ob['subject'].'</option>';
}
}
echo '</select>';
#3
0
You're trying to use properties, it's an array not an object.
您正在尝试使用属性,它是一个数组而不是对象。
You need to use $ob['----'] instead of $ob-> notation
你需要使用$ ob ['----']而不是$ ob->表示法
echo '<select>';
foreach ($webinars as $obj)
{
foreach ($obj['webinars'] as $ob)
{
echo '<option value='.$ob['webinarKey'].'>'.$ob['subject'].'</option>';
}
}
echo '</select>';
#1
1
$data = array(/**/);
foreach ($data["upcoming"]["webinars"] as $webinar) {
echo '<option value="' . htmlspecialchars($webinar["webinarKey"]) . '">' . htmlspecialchars($webinar["subject"]) . '</option>';
}
From what I gather the only array you need to loop over is $data["upcoming"]["webinars"]
.
从我收集的内容中,您需要循环的唯一数组是$ data [“coming”] [“webinars”]。
Ensure your output HTML is valid and your data is escaped properly.
确保输出HTML有效,并且您的数据已正确转义。
#2
0
Since you are trying to access a value in a multidimensional array, you cannot use ->
as that is for properties of objects. Instead you need to access it like a normal array: $array[key]
由于您尝试访问多维数组中的值,因此不能使用 - >,因为它适用于对象的属性。相反,你需要像普通数组一样访问它:$ array [key]
Updated Code:
更新的代码:
echo '<select>';
foreach ($webinars as $obj)
{
foreach ($obj['webinars'] as $ob)
{
echo '<option value='.$ob['webinarKey'].'>'.$ob['subject'].'</option>';
}
}
echo '</select>';
#3
0
You're trying to use properties, it's an array not an object.
您正在尝试使用属性,它是一个数组而不是对象。
You need to use $ob['----'] instead of $ob-> notation
你需要使用$ ob ['----']而不是$ ob->表示法
echo '<select>';
foreach ($webinars as $obj)
{
foreach ($obj['webinars'] as $ob)
{
echo '<option value='.$ob['webinarKey'].'>'.$ob['subject'].'</option>';
}
}
echo '</select>';