I have a list of optional clothing items as checkboxes, there may be a greater number than the 5 below.
Код: Выделить всё
shoes, pants, skirt, socks, jacket //list of possible choices
Код: Выделить всё
shoes, socks, jacket //array posted as $_POST['clothes']
'clothes' table before insert
Код: Выделить всё
customer_id dress_shoes elegant_pants long_skirt ankle_socks biker_jacket
1 no yes no no no
Код: Выделить всё
yesКод: Выделить всё
no'clothes' table after insert
Код: Выделить всё
customer_id dress_shoes elegant_pants long_skirt ankle_socks biker_jacket
1 yes no no yes yes
Код: Выделить всё
array_intersect()Код: Выделить всё
$clothesArray = array("shoes", "socks", "jacket"); // Posted clothes
$clothesArrayAll = array("shoes", "pants", "skirt", "socks", "jacket"); // All clothes
$common = array_intersect($clothesArrayAll,$clothesArray);
print_r($common);
Array ( [0] => shoes [3] => socks [4] => jacket )
Код: Выделить всё
$clothesArrayAllИсточник: https://stackoverflow.com/questions/125 ... -using-pdo
Мобильная версия