<form action="" method="post">
<label>
0001
<input name="nic[]" value="0000-0000-0000-0001" type="checkbox" />
</label>
<label>
0002
<input name="nic[]" value="0000-0000-0000-0002" type="checkbox" />
</label>
<input type="submit" />
</form>
Array
(
[nic] => Array
(
[0] => 0000-0000-0000-0001
[1] => 0000-0000-0000-0002
)
)
$data = [
'type' => 'Рабочая станция',
// ...
'nic' => [
'0000-0000-0000-0000',
'0000-0000-0000-0001'
],
'license' => [
'0',
'1'
]
];
<?php
echo '<pre>'.print_r($_POST,1).'</pre>';
?>
<form action="" method="post">
<input name="nic[]" value="0000-0000-0000-0001" />
<input name="nic[]" value="0000-0000-0000-0002" />
<span class="add_nic">добавить nic</span>
<input type="submit" value="ok" />
</form>
<script type="text/javascript">
document.querySelector('.add_nic').addEventListener(
'click',
function(e) {
var inp = document.createElement('input');
inp.setAttribute('name', 'nic[]');
this.parentNode.insertBefore(inp, this);
}
);
</script>
<?php
class dataConverter {
public function addHandler($closure, $rex = null)
{
}
public function __construct()
{
// добавляем дефолтные обработчики
$this->addHandler(
function($k, $v, $matches) {
// [значение, ключ, сохранять_как_массив]
return [$matches[1], 'nic', true];
},
'~^nic(\.+)$~'
);
}
public function convert($data)
{
foreach ($data as $k => $v) {
foreach ($this->handlers as $handler) {
// проверяем
}
}
}
}
class UserGroup {
const SEKRETARSHA = 1;
const ADMIN = 2;
}
...
if ($user->group_id === UserGroup::SEKRETARSHA) { ... }