我正在尝试使用PHP来解析XML列表,并使用datepicker过滤和分页结果以匹配隐藏输入的选定日期。但是,当尝试使用PHP搜索我的数组时(在转换为json并返回到php数组之后),我没有输出。任何有关这方面的帮助都会很棒!
我的代码:
function LoadXML()
{
$xmlURL = 'http://rhpl.evanced.info/signup/eventsxml.asp?dm=xml&lib=all&alltime=1&ds=&ds=6/15/2016&de=6/15/2018';
$xmlFile = simplexml_load_file($xmlURL);
$json = json_encode($xmlFile);
$array = json_decode($json,TRUE);
$selectedDate = $_POST['selectedDate'];
echo "<pre>";
$search = array_search($selectedDate, $array);
echo $search;
foreach ($array['item'] as $item) {
$title = $item['title'];
$date = $item['date'];
//echo "<div id='event-item'>";
//echo "<span id='title'>" . $title . "</span>" . "<br />";
//echo "<span id='date'>" . $date . "</span><br/>";
//echo "</div>";
}
//print_r($array);
echo "</pre>";
}
我的数组输出:
Array
(
[item] => Array
(
[0] => Array
(
[title] => English Matters Book Group for English Language Learners
[date] => Wednesday, June 15, 2016
[time] => 10:00 AM
[enddate] => Array
(
)
[description] =>
Wednesday Mornings, 10 -11:30, Second Floor Conference room
答案 0 :(得分:1)
<强>尝试:强>
$search = array_search($selectedDate, array_column($array, 'date'));
您需要确定要进行搜索的列。使用array_column(),您可以选择所需的数组列,&#39; date&#39;。