Q:

Group Parsed XML Elements with PHP

What I am working with is a list of sightings for birds for an area. Sometimes the same bird is reported twice or three times. I want to group all sightings of a particular bird by it's name and then display the location names for the sightings.
This is what i'm working with so far, and getting no output..going on 8 hours..time to ask for help.
Here is a sample url of $noteable 
http://ebird.org/ws1.1/data/notable/geo/recent?lng=-110.7576749&lat=32.4432180&detail=full&hotspot=true&dist=15&back=10
<?php
    $notexml = simplexml_load_file($noteable);
    $typesListXml = $notexml->xpath("result/sighting/com-name"); 

    if (!empty($typesListXml)) {
        $typesList = array();
        foreach ($typesListXml as $typeXml) {
            $typesList[] = (string)$typeXml;
        }
        $typesList = array_unique($typesList);

        $nameForType = array();
        foreach ($typesList as $type) {
            $rawData = $xml->xpath('result/sighting[com-name="' . $type . '"]');
            if (!empty($rawData)) {
                foreach ($rawData as $rawName) {
                    $nameForType[$type][] = $rawName->{'loc-name'};
                }
            }
        }

        var_dump($nameForType); // var_dump #4
    } 
}
?>

A:

How about something like this?
<?php
    $noteable = 'http://ebird.org/ws1.1/data/notable/geo/recent?lng=-110.7576749&lat=32.4432180&detail=full&hotspot=true&dist=15&back=10';
    $xml = simplexml_load_file($noteable);
    $result = array();
    foreach ($xml->result->sighting as $sighting) {
        $location = (string) $sighting->{'loc-name'};
        $bird = (string) $sighting->{'com-name'};
        if (!isset($result[$bird])) $result[$bird] = array();
        $result[$bird][] = $location;
    }
    print_r($result);

For the XML file you included above, it produces the following output:
Array
(
    [Buff-breasted Flycatcher] => Array
        (
            [0] => Mt. Lemmon--Rose Canyon and Lake
            [1] => Mt. Lemmon--Rose Canyon and Lake
            [2] => Mt. Lemmon--Rose Canyon and Lake
        )

    [Northern Goshawk] => Array
        (
            [0] => Mt. Lemmon--Rose Canyon and Lake
        )

)

If you want to avoid reporting duplicate locations for the same bird, you could add an array_unique call to the end of the loop:
$result[$bird] = array_unique($result[$bird]);

