I’m using a multidimensional array in a form and I want to parse these values into a serialized array to be stored in my database. Here’s the relevant section of my HTML form:
<select name="week_days[monday]"><option value=""></option><option value="preferred">Preferred</option><option value="restricted">Restricted</option></select>
<select name="week_days[tuesday]"><option value=""></option><option value="preferred">Preferred</option><option value="restricted">Restricted</option></select>
<select name="week_days[wednesday]"><option value=""></option><option value="preferred">Preferred</option><option value="restricted">Restricted</option></select>
<select name="week_days[thursday]"><option value=""></option><option value="preferred">Preferred</option><option value="restricted">Restricted</option></select>
I want to then create an array in my model called week_days. An example of what I want the array to look like is this:
array('monday'=>'preferred','tuesday'=>'','wednesday'=>'restricted','thursday'=>'');
I will then serialize() this array for storage in my database. How do I go about converting the multidimensional array input into an array for serialization?
When you submit this in a form, you will get a
$_POST['week_days']which will be equal to your array in your question