Array reading with php

1

Good afternoon, I have this array that comes from $ form variables

Array
(
    [nome] => 765hygfy
    [data_nascimento] => ftyftyf
    [email] => [email protected]
    [sexo] => Feminino
    [rg] => ytfytfyt
    [cpf] => fytfty
    [telefone_residencial] => fty
    [telefone_celular] => fyt
    [telefone_recado] => 
    [cep] => fytf
    [estado] => MS
    [cidade] => fytfytf
    [bairro] => ytf
    [logradouro_rua] => ftyf
    [numero] => tyfyt
    [complemento] => fty
    [referencia] => fytf
    [onde_conheceu] => FaceBook
    [revendeu_outras_marcas] => Não
    [quais] => ytftyf
    [horario_de_contato] => Manhã
)

They are coming from a form like the names in this pattern

form[nome]
form[email]

And so it goes

What I need to do is php read this array by printing the key after the value I have already made several foreach to a for and return blank.

My foreach

foreach($_POST['form'] as $key => $value){ 
  $nome = arrumanome($key);
  $msg.= $nome.": ".$value."<br>";
}

It returns only this aki

:
:
:
:
:
:
:
:
    
asked by anonymous 16.01.2017 / 18:21

1 answer

0

Boy, it looks like you've submitted the form blank or your arrumanome function is modifying your data and leaving it blank.

See if the following code, which works properly, helps you:

An html form with some of your data to test:

<form action="foreach.php" method="post">

    <input type="text" name="form[nome]" value="Nome Teste"><br>
    <input type="text" name="form[data_nascimento]" value="31/01/1980"><br>
    <input type="text" name="form[email]" value="[email protected]"><br>
    <input type="text" name="form[sexo]" value="Masculino"><br>
    <input type="text" name="form[rg]" value="123456789"><br>
    <input type="text" name="form[cpf]" value="1198765432"><br>

    <input type="submit" value="Enviar">

</form>

foreach.php

<?php

$dados_post = $_POST["form"];

$msg='';

foreach($dados_post as $key => $value)
{
    $msg.= $key . ": " . $value . "<br>";
}

echo $msg;

On-screen result:

nome: Nome Teste
data_nascimento: 31/01/1980
email: [email protected]
sexo: Masculino
rg: 123456789
cpf: 1198765432
    
16.01.2017 / 20:04