Print values from the same variable via GET PHP

Asked

Viewed 363 times

0

I need to print on the screen the values of the same variable via $_GET, as the example below.

http://localhost/sistema/cadastro_usuario.php?cod_igreja=4355&nome_user=Renan&[email protected]&celular=67992341353&cod_depto=20&cod_depto=10&cod_depto=35

Can someone help me?

  • I removed the [dynamic-programming] tag because it has nothing to do with dynamic programming. The other tags, too, because it’s not just because you use mysql or html in the project, which means this question has to do with it directly.

3 answers

1

If I understand correctly you can do the following:

foreach($_GET as $key => $val) {
    echo $key. ': ' .$val;
}

In which $key will be for example cod_igreja and the $val respective will be 4355 in the example you gave

To print only the value of one, in this case cod_igreja:

echo $_GET['cod_igreja'];

1

Variable cod_depto is repeated. Then, only the last one will be displayed. In case, you need to turn it into an array to pass via get, by placing the []:

http://localhost/sistema/cadastro_usuario.php?cod_igreja=4355&nome_user=Renan&[email protected]&celular=67992341353&cod_depto[]=20&cod_depto[]=10&cod_depto[]=35

//Então, na hora de imprimir os valores de cod_depto, você faz:

$cod_deptos = $_GET['cod_depto'];
foreach($cod_deptos as $cod_depto){
    echo $cod_depto . "<br />";
}

0

If you want to debug your code, you should actually try to configure the use of Xdebug with your text editor of choice, instead of debugging in the print base.

  • Phpstorm - I believe it comes along
  • Visual Studio Code - Install the plugin
  • Sublime Text - Install the plugin. The integration in Sublime is a little strange, however.

For debug in the base Usitana has the var_dump() and the print_r().

Browser other questions tagged

You are not signed in. Login or sign up in order to post.