calvin182 Posted March 28, 2006 Share Posted March 28, 2006 I have an array and what I want to do is when a file is uploaded to the server through my form, I want the date and file name to be added to an array(date as the key and file name as the contents of the key) in a php file dedicated only to the array (acting like a database kind of).How do I add a new key and value to an already existing array. I know how to do all of the saving function stuff for this. Also at some point I'll probably be interested in removing a key after I search for it. If you know how to do any of this your help would be much appreciated!-Calvin Link to comment Share on other sites More sharing options...
DarkElf Posted March 29, 2006 Share Posted March 29, 2006 Sounds like a fun one.I'm assuming you know the basics of manipulating arrays, e.g. you can modify the value of key called key1 in an array called array by doing this: $array['key1'] = value If that key doesn't exist then that statement will create it.Now for the complicated bit:If you're using numeric keys then you could load the array and count the number of keys, then add the new key with a numeric identifier of that number (note you don't need to increment it because default numeric keys start from 0 not from 1). Does that make sense and/or help? Sorry I don't have time to work out the code for it right now. If you're still stuck and no-one else comes to your aid I'll try and work it out. I think there is a function that will count the number of terms stored in an array for you but i can't recall it off the top of my head. Link to comment Share on other sites More sharing options...
calvin182 Posted March 29, 2006 Author Share Posted March 29, 2006 okay thatsolves creating. so I can name the keys to be whatever right? I want to basically use the date when that specific key was created as the key name and the file name as the value so later I can sort out all of my images by the date they were uploaded. Then if the user does not want to share an image anymore, they can delete the entry from the array and the image (i think i can work that out).I'm thinking that the keys would this format:$array['03-27-2006-01'] = "DSCN5341.jpg"$array['03-27-2006-02'] = "DSCN5349.jpg"$array['03-29-2006-01'] = "DSCN5401.jpg"so when i load this array, I'll do a quick sort so that the most recent entry is first, though I'm not sure if my numbering pattern after the date is the best idea. I'm not sure yet. at the moment im just trying it step by step, so t he next step is to delete keys. Link to comment Share on other sites More sharing options...
DarkElf Posted March 30, 2006 Share Posted March 30, 2006 to delete a variable, array, or just one part of an array you can use the unset function: unset($array['key']) Link to comment Share on other sites More sharing options...
reportingsjr Posted March 30, 2006 Share Posted March 30, 2006 Clavin, If you want it to be an array (holds many variables) why do you has a different array for each one? Link to comment Share on other sites More sharing options...
calvin182 Posted March 30, 2006 Author Share Posted March 30, 2006 (edited) im not sure, I don't fully understand arrays completely yet. would i do something like this:$files = array();$files['03-27-2006-01'] = "DSCN5341.jpg";$files['03-27-2006-02'] = "DSCN5349.jpg";$files['03-29-2006-01'] = "DSCN5401.jpg";krsort($files);print_r($files); Edited March 30, 2006 by calvin182 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now