Ti suggerisco di iniziare leggendo il manuale ufficiale:

http://www.php.net/glob
http://www.php.net/foreach
http://www.php.net/print