Php 用另一个数组为数组设置关键帧?
我在下面有一个数组:Php 用另一个数组为数组设置关键帧?,php,arrays,Php,Arrays,我在下面有一个数组: "checkbox_1": [ "1" ], "checkbox_2": [ "0" ], "checkbox_3": [ "0" ], "checkbox_4": [ "0" ], "checkbox_5": [ "0" ], "checkbox_6": [ "0" ], "checkbox_7":
"checkbox_1": [
"1"
],
"checkbox_2": [
"0"
],
"checkbox_3": [
"0"
],
"checkbox_4": [
"0"
],
"checkbox_5": [
"0"
],
"checkbox_6": [
"0"
],
"checkbox_7": [
"0"
],
"checkbox_8": [
"0"
]
我想知道使成对阵列有效存储标签的最佳方法:
$checkboxes = array('text value', 'text value, 'text value', '..');
如果复选框_1为1,则查找文本值并输出
我试过一种方法,但觉得有一种很好的方法
array\u intersect\u键可以帮助您。我看起来很干净
$c = [
'a'=>1,
'b'=>0,
'c'=>1,
'd'=>0,
'e'=>0,
'f'=>1
];
$d = [
'asd1',
'asd2',
'asd3',
'asd4',
'asd5',
'asd6'
];
print_r(array_intersect_key($d, array_filter(array_values($c))));
结果
Array
(
[0] => asd1
[2] => asd3
[5] => asd6
)
让我们检查数组映射
或数组漫游
函数。您可能错过了一个引号。最好让JavaScript将复选框作为数组提交,即[1,0,0,0,0,…]
。