Results 1 to 10 of 10
Nov 2, 2012, 22:12 #1
- Join Date
- Jun 2008
- Madison, WI
- 31 Post(s)
- 0 Thread(s)
best practice...json_encode OR serialize?
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:
$putIntoDB1=serialize($storeMe); // OR $putIntoDB1=json_encode($storeMe);
$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 appreciatedTips for better/ faster SitePoint forum answers
Brilliant ideas, elegant execution.
Graphic Design, Art Direction, Copywriting and Web Design.