问题描述
我正在尝试从3个不同的数组创建单个事件PHP数组,这些数组是从xml文件创建的。我目前拥有的阵列是:
场地 - 来自venuesList xml节点
标题 - 来自titleList xml节点
事件 - 来自eventList xml节点
eventList->事件xml节点具有venueID和titleID的属性。我随后需要创建一个包含事件的数组,使用venueID和titleID属性将正确的场地和标题数据与正确的事件合并。
我正在提取的信息每个阵列中的内容如下:
场地 - 具有venueID属性
- 场地名称
- 类别
- 场地地址
- disabledAccess
- 网站
标题 - 具有titleID属性
- 类别
- 网站
- 描述
活动 - 有titleID和sceneID属性
- eventName
- 场地ID
- titleID
我需要一个包含以下内容的数组:
事件数组
- eventName
- venueName
- 类别
- 场地地址
- disabledAccess
- 网站
- 类别
- 网站
- d escription
我的代码如下:
I am trying to create a single events PHP array from 3 different arrays that are created from an xml file. The arrays I currently have are:
Venues - Comes from the venuesList xml node
Titles - Comes from the titleList xml node
Events - Comes from the eventList xml node
The eventList->event xml node has attributes for venueID and titleID. I subsequently need to create an array with events, merging the correct venue and title data with the correct event using the venueID and titleID attributes.
The information I am currently pulling in from each array is as follows:
Venues - has venueID attribute
- venueName
- categories
- venueAddress
- disabledAccess
- website
Titles - has titleID attribute
- categories
- website
- description
Events - has titleID and venueID attributes
- eventName
- venueID
- titleID
I require an array with the following:
Events Array
- eventName
- venueName
- categories
- venueAddress
- disabledAccess
- website
- categories
- website
- description
My code is as follows:
$value) { $i++;
//if($i<2) {
if($value==$date.'0822_ope_full.xml') {
$xml=simplexml_load_file('ftp://southwark:jqA3%[email protected]/'.$value.'');
// Venues
echo "Venues";
$venuesarray = array();
foreach($xml->venueList->venue as $venue) {
$venuearray = array();
foreach($venue as $key => $value) {
$venuearray[(string)$key] = (string)$value;
$venuearray['venueID'] = (string)$venue['venueID'];
}
$venuesarray['venueList'][] = $venuearray;
echo 'Venue Name: '.$venue->venueName.'';
echo 'Venue Address: '.$venue->venueAddress->streetName.', '.$venue->venueAddress->district.', '.$venue->venueAddress->town.', '.$venue->venueAddress->county.', '.$venue->venueAddress->postcode.'';
echo 'Credit Card Tel: '.$venue->creditCardTel.'';
echo 'Disabled Access: '.$venue->disabledAccess.'';
echo 'Phone: '.$venue->phone->dialcode.' '.$venue->phone->phonenumber.'';
echo 'Transport: '.$venue->venueTransport.'';
echo 'Email: '.$venue->email.'';
echo '';
}
// Titles w/ Categories
echo "Titles";
$titlesarray = array();
foreach($xml->titleList->title as $title) {
$titlearray = array();
foreach($title as $key => $value) {
$titlearray[(string)$key] = (string)$value;
$titlearray['titleID'] = (string)$title['titleID'];
}
$titlesarray['titleList'][] = $titlearray;
echo 'Title: '.$title->titleName.'';
echo 'Categories: ';
foreach ($title->categories->category as $cat) {
echo $cat['name'].', ';
} echo '';
echo 'Website: '.$title->website.'';
echo 'Description: '.$title->description['standard'].'';
echo "";
}
// Events
echo "Events";
$eventsarray = array();
foreach($xml->eventList->event as $event) {
$eventarray = array();
foreach($event as $key => $value) {
$eventarray[(string)$key] = (string)$value;
$eventarray['eventID'] = (string)$event['eventID'];
$eventarray['venueID'] = (string)$event['venueID'];
$eventarray['titleID'] = (string)$event['titleID'];
}
$eventsarray['eventList'][] = $eventarray;
echo 'Event: '.$event->eventName.'';
echo 'Title ID: '.$eventarray['titleID'].'';
echo 'Venue ID: '.$eventarray['venueID'].'';
echo "";
}
}
}
// close connection
ftp_close($ftp_conn);
?>
我尝试了什么:
我尝试合并数组但是这并没有给我所需的结果
What I have tried:
I have tried merging the arrays but this doesn't give me the required outcome
推荐答案
这篇关于如何使用正确的数据创建单个PHP数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!