Submit Multidimensional Array

2

I have a Form with input checkbox and text

'<input type="checkbox" name="formandos_servicos[]" value="'+data['id']+'">'+
'<input type="text" name="nome_funcionario_servicos[]" value="'+data['title']+'" >'+
'<input type="text" name="naturalidade_servicos[]" value="'+data['naturalidade']+'" placeholder="Naturalidade">'+

I count the input that is loaded in Form

for($i = 0; $i < $count; $i++) {
$data[] = array(
'formandos_servicos' => $formandos_servicos[$i],
'nome_funcionario_servicos' => $nome_funcionario_servicos[$i]
);
}

In print_r ($ data) the result is:

[1] => Array
(
[formandos_servicos] => 680
[nome_funcionario_servicos] => Alberto Damião Pimenta
)

[2] => Array
(
[formandos_servicos] => 678
[nome_funcionario_servicos] => Celestino José Faria Oliveira
)

The result of [formand_services] corresponds to the 2nd and 3rd checked checkbox. The result of [service_function_name] corresponds to the 1st and 2nd input text.

Someone, please know how to match the checkbox with the input text?

    
asked by anonymous 30.08.2018 / 21:05

1 answer

0

From the checkbox group with the name "formand_services []" only those that are marked (checked) will be sent. The other elements are sent all but the match at the time of receiving will be according to the indexing of the received checkboxes. A foreach is more suitable:

foreach ($formandos_servicos as $index => $value) {
        $data[] = array(
            'formandos_servicos' => $value,
            'nome_funcionario_servicos' => $nome_funcionario_servicos[$index]
        );
}
    
25.09.2018 / 20:03