Click here to Skip to main content
15,898,222 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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:
PHP
$value) { $i++;
    //if($i<2) {

    if($value==$date.'0822_ope_full.xml') {
        $xml=simplexml_load_file('ftp://southwark:jqA3%Rpn@ftp.howden.press.net/'.$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
Posted
Updated 11-May-16 5:46am
v2
Comments
Patrice T 11-May-16 16:58pm    
"this doesn't give me the required outcome "
is not informative

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900