Best way of getting a a series of custom fields into an array?

This way of wokring with slides seems to be as popular as it is terrible… 🙂 I coded something very much like this recently.

Basic idea, adjust as needed:

$id = get_the_ID();
$slides = array();
$i = 1;    

foreach( get_post_custom_keys( $id ) as $key )
    if ( false !== strpos( $key, 'slide' ) )
        $slides[$key] = get_post_meta( $id, $key, true);

while( isset( $slides["slide{$i}"] ) ) {

    echo '<img src="' . wp_get_attachment_url( $slides["slide{$i}"] ). '" />';
    $i++;
}