Am trying to store array information gathered from a form. The form is dynamic s the info can include a different number of fields and different names. As such it seems the best way to package the info is in an array or multidimensional array and then store that array into the DB.
There seems to be two ways to do this: serialize() or json_encode() I was wondering which one is be considered the best practice.
So for example the form could have any # of text inputs named detail/ paired with any number of selects named detailKind, it also has a variable set of single fields … named: samples
after the form is submitted encode the info as such:
$storeMe=array(‘detailKind’=>$_POST[‘detailKind’], ‘detail’=>$_POST[‘detail’]);
$putIntoDB1=serialize($storeMe); // OR $putIntoDB1=json_encode($storeMe);
$sampleStore=$_POST[‘samples’];
$putIntoDB2=serialize($sampleStore); // OR $putIntoDB1=json_encode($storeMe);
I like JSON because the data remains readable in it’s stored form; you can even edit the JSON text w/o corrupting the object! BUT multidimensional arrays get stored as objects and not arrays which means an extra checking and extraction step.
Serialize() keeps everything in array form, but is not as pretty ( or mailable ) after encoding.
Which methods would the forum experts favour?
Thanks again, as always your insights are greatly appreciated