0

i have a $_POST array from form submission. My datas are:

Array (
[codice_fiscale] => CODICEFISCALE 
[sesso] => F 
[comune_nascita] => H501 
[anno_nascita] => 82 
[mese_nascita] => 03 
[giorno_nascita] => 13
 )  

i need to print,foreach value, a string like the follow, in order to put it in a Ajax variables form:

codice_fiscale: CODICEFISCALE,
sesso: F,
comune_nascita: H501,
anno_nascita: 82,
mese_nascita: 03,
giorno_nascita 13

I've tried this

foreach($_POST as $key => $value){

   echo $key.' : "'.$value.'",</br>';}

but , of course, he puts the dot also at the last element.

How can i fix it?

1 Answers1

0

Put the strings in an array and join them with implode().

$array = [];
foreach ($_POST as $key => $value) {
    $array[] = "$key: $value";
}
echo implode(',<br>', $array);
Barmar
  • 741,623
  • 53
  • 500
  • 612