It is not possible to store arrays in beans because RedBeanPHP cannot predict how you want the array to be represented in the database.
The decision depends on what you want to do with this information later. You want to add other things, and not just on weekdays, for example, in the evening or overtime (in case of planning?), In this case, I would choose the most flexible and easy solution:
//Flexible solution foreach($days as $day) $user->sharedDay[] = R::findOne('day',' name = ? ',array($day));
Since we use sharedDay instead of ownDay, records will not be duplicated. This solution creates a neat day_user reference table.
Of course, you need to store weekly days in the database once:
$days = array('monday',...); foreach($days as $dayname) { $d = R::dispense('day'); $d->name = $dayname; R::store($d); }
If you want to be able to quickly track a user with a specific profile of the day of the week, you can encode days:
//Performance solution function days($days) { $weekdays = array('sunday','monday','tuesday',...); $field = ''; foreach($weekdays as $day) { $field .= (in_array($day,$days)) ? '1' : '0'; } return $field; } $user->days = bindec(days($days));
In this case, you can find each user having "Monday" and "Saturday" by asking: days = 33. This is very fast.
If you do not need data at all, you can:
//Quick and dirty solution $user->days = implode(',',$days);