wisewood Posted April 26, 2006 Share Posted April 26, 2006 The title doesn't really do justice the the question to be honest.I have an array, which is loaded up with all the filenames of files in a given directory.Now, what i want to do, is create a drop down list using <SELECT>, which will let me specify which types of file i would like to view... ie .bmp, .php, .jpg, .asp, .txt etc etc.I have ALOT of files in this directory, and want to be able to narrow it down somewhat by choosing what file types i want to browse.I know i can use a substr() function to get the extension of the files, but can i then create an array only containing one entry for each of the file types, so i would end up with something like;<SELECT><OPTION>asp</OPTION><OPTION>bmp</OPTION><OPTION>gif</OPTION><OPTION>jpg</OPTION><OPTION>php</OPTION><OPTION>txt</OPTION></SELECT>I've already checked out the php.net/array pages and can't find anything that seems to be pointing me in the right direction. Quote Link to comment https://forums.phpfreaks.com/topic/8449-array-problem/ Share on other sites More sharing options...
samshel Posted April 26, 2006 Share Posted April 26, 2006 Hello,Try this,[code]<?php $filenames = array ("abc1.txt","abc2.jpg","abc3.png","abc4.txt");//this is the array which contains ur filenames$extension_arr = array();foreach($filenames as $key=>$val) { $arr = explode(".",$val); $extension = $arr[1]; $extension_arr[$extension][] = $val;}$extensions = array_keys($extension_arr));//this array will contain all the extensions without duplicates//array $extension_arr will contain extension wise filenames which can be used to display files belonging to a particular extension.?>[/code]hth Quote Link to comment https://forums.phpfreaks.com/topic/8449-array-problem/#findComment-30900 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.