Re: Storing key values in an array
| From: | Jochem Maas | Date: | Fri, 21 Jan 2005 20:02:07 +0000 |
| Subject: | Re: Storing key values in an array | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-206979@lists.php.net to get a copy of this message | ||
Todd Cary wrote:
I am using an array to populate a drop-down and I would like to have the same value in the key as the value. Using the following, the key is 0,1,2,3...etc. How can I correct that?what is there to correct - you are telling me that the value of $file show up as a string and then magically it becomes an integer (but just while you are designating the key) listen you've just shown us a simple loop to stuff some file/dir names into an array where by the file/dir name is the assoc. key as well as the value of any given item in said array - WHERE THE F*** IS THE DROPDOWN RELATED CODE?
$file_list = array();
$dir = opendir($doc_dir);
while (false !== ($file = readdir($dir))) {
if (($file != ".") && ($file != ".."))
$file_list[$file] = $file; <---------------<<<<<
}
what happens if you place the following right after the code you mention (just to prove that what you say about the key is wrong):
echo '<pre>';
print_r($file_list);
echo '</pre>';
Todd