possien Posted January 1, 2012 Share Posted January 1, 2012 I am creating a poll with a form using check boxes. The resulting associative array is evaluated and 1 is to be added to values selected. I have that part down. I want to write the associative array to a file and the next time someone uses the form the values are read from the file, values added and then write it back to a file. I thought it would be better to do it like this rather than query a db, add values, etc. Any ideas on how to do this? This is the array I want to start with: $vetservice = array( "Korea"=>0, "Vietnam"=>0, "Grenada"=>0, "Cold War"=>0, "Panama"=>0, "Desert Storm"=>0, "Mogadishu"=>0, "OEF"=>0, "OIF"=>0 ); Values from the post array would be added to the starting value and wrote back to a text file. Link to comment https://forums.phpfreaks.com/topic/254148-writing-and-reading-an-associative-array-to-file/ Share on other sites More sharing options...
AyKay47 Posted January 1, 2012 Share Posted January 1, 2012 imo I would use a database for this along with serialize and unserialize. Link to comment https://forums.phpfreaks.com/topic/254148-writing-and-reading-an-associative-array-to-file/#findComment-1302944 Share on other sites More sharing options...
possien Posted January 1, 2012 Author Share Posted January 1, 2012 Thats great, I didn't know these existed. So basically I just read/write the array to the db instead of separate values . Link to comment https://forums.phpfreaks.com/topic/254148-writing-and-reading-an-associative-array-to-file/#findComment-1302948 Share on other sites More sharing options...
AyKay47 Posted January 1, 2012 Share Posted January 1, 2012 Thats great, I didn't know these existed. So basically I just read/write the array to the db instead of separate values . yes, use serialize to convert the array to a string for db storage, then unserialize to convert it back into an array after selecting it form the db. Link to comment https://forums.phpfreaks.com/topic/254148-writing-and-reading-an-associative-array-to-file/#findComment-1302950 Share on other sites More sharing options...
possien Posted January 1, 2012 Author Share Posted January 1, 2012 Thanks AyKay47, Your suggestions works great. I used google graphs to display the data. You can see it at http://www.vvaarizona.org/index.php Link to comment https://forums.phpfreaks.com/topic/254148-writing-and-reading-an-associative-array-to-file/#findComment-1303020 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.