You can store the array using serialize
/unserialize
. With that solution they cannot easily be used from other programming languages, so you may consider using json_encode
/json_decode
instead (which gives you a widely supported format). Avoid using implode
/explode
for this since you'll probably end up with bugs or security flaws.
Note that this makes your table non-normalized, which may be a bad idea since you cannot easily query the data. Therefore consider this carefully before going forward. May you need to query the data for statistics or otherwise? Are there other reasons to normalize the data?
Also, don't save the raw $_POST
array. Someone can easily make their own web form and post data to your site, thereby sending a really large form which takes up lots of space. Save those fields you want and make sure to validate the data before saving it (so you won't get invalid values).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…