Thursday, May 6, 2010

Facebook Arrays

Helping a friend out with a Facebook application and I had to deal with an array of array export from a multiquery FQL.  Sheeesh, fields and values mis-matched all over the place!  However, using dynamic PHP arrays it makes it a little easier with the following code.

#Multiout is the array delivered from the FQL

foreach($multiout as $fqlset) { #Strip the wrapper array
    $messagebody = $fqlset[fql_result_set];
        foreach ($messagebody as $messageArray) {   #Strip the message vs. metadata
            foreach ($messageArray as $key => $value) {  #Finally get to drop the 'record name' and value
            $ordered_array[$key][] = $value;
        }      
    }
}

At the end of the process, you have an ordered array that was combined by the multiquery.

No comments: