When I was engaged in PHP, I found that the | and & operators are very clever. I would like to share with you this article.
Bitwise operator | and & Simplified checkbox check box access value. Set the name attribute of the checkbox to name = "certified_type []". After cyclically setting the value (value is set to 1, 2, 4, and so on) of all elements in certified_type to the Npower of 2, n> = 0, bitwise OR, the final result is saved to the database as an int type.
The result retrieved from the database can be located in the check boxes by bitwise AND operations. // For example, there are three checkboxes, value = 1, 2, and 4. If we select 1 and 4, the certified_type [] value we get is, the value obtained after bitwise OR operation in the first step is
001 1
100 4
----- |
101 5
The value of the checkbox to be stored in the database is 5, and 5 is used to perform bitwise AND operations on the value of the checkbox to be determined, if it is true, it is selected. For example, if 5 & 1 is true, the checkbox with value = 1 is selected, and 5 & 2 is false, the box with value 2 is not selected.
101 5 101
001 1 010
-----&-----&
001 1 true 000 false
Practical Use of bitwise OR and bitwise in projects