I'm posting the below arrays, where each checkbox/checkbox tag are linked with a key (i.e. each category check box is linked with a "worldwide" checkbox):
<input type="checkbox" name="catpref[1]" value=10 > Politics
<input type="checkbox" name="worldwide[1]" value=1 > Worldwide
<input type="checkbox" name="catpref[2]" value=20 > Sports
<input type="checkbox" name="worldwide[2]" value=1 > Worldwide
I received them in the controller and trying to store the values.
$catprefs = $request['catpref'];
$worldwide = $request['worldwide'];
foreach($catprefs as $key => $value and $worldwide as $key => $value2){
$save_catp = new Cpref();
$save_catp->user_id = $user_id;
$save_catp->qatype = $value;
$save_catp->wwide= $value2;
$save_catp->type = 1;
$save_catp->save();
What would be the syntax for the above foreach loop ?
P.S : Please note that the arrays linked together via key could be different in size because a category could be selected while "worldwide" could be left unselected (i.e. array_combine() requires equal size arrays).