Jump to content

Writing and Reading an associative array to file


possien

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.