arrays

liunx

Guest
does anyone know how to select one item out of an array at a time the PHP book i have only shows me how to loop trough them or print the whole group at once
i need to only get one item at a time heres pritty much what im looking for

the array:
$icon = array("zip.gif", "rar.gif", "folder.gif", "exe.gif");

I have it going through a DIr script that finds all the docs/files in a DIr and i want to print a image next to it like apache does but apache dont knoe rar, php, and all the third party files

can anyone help?
thanks

longbowRead the PHP Manual on arrays (<!-- m --><a class="postlink" href="http://www.php.net/manual/en/language.types.array.php">http://www.php.net/manual/en/language.types.array.php</a><!-- m -->).Hi

Just set your image icon array to use keys that relate to the file extension you have found in your directory reading script!

simple example...



$icons = array (
'gif' => array ( 'gif.gif', 'image/gif' ),
'doc' => array ( 'msdoc.gif', 'application/msword' ),
'unknown' => array ( 'ostrm.gif', 'application/octet-stream' )
);

while(reading_directory)
{
$ext = substr ( $file, ( strrpos ( $file, '.' ) + 1 ) );

$info = stat ();

if ( ! isset ( $icons[$ext] ) )
{
$ext = 'unknown';

}

// build the directory array for the display, makes sorting easy! -> array_multisort();

$files[] = array (
'name' => $file,
'path' => $dir . '/' . $file,
'size' => $info[7],
'date' => date ( 'r', $info[9] ),
'icon' => $icons[$ext][0],
'type' => $icons[$ext][1]
);

} // end while read dir

clearstatcache ();





abc
 
Back
Top