wordpress output numbers from an array of checkboxes


I’m not a php expert at all, but I’ve just started to learn it. I’m using a function on wordpress which creates a xml file after pressing send button on a contact form (with contact form 7). That’s my code for the moment:

add_action( 'wpcf7_before_send_mail', 'CF7_pre_send' );  function CF7_pre_send($  cf7) {     $  output = "";     $  output .= "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";     $  output .= "<cf>" . $  _POST['codicefiscale'] . "</cf>";     $  output .= "<cognome>" . $  _POST['cognome'] . "</cognome>";      .......      $  output .= "<aree_tematiche>";     $  output .= "<area><macroarea>1</macroarea><subarea>" . implode(', ', $  _POST['area1']) . </subarea></area>";       $  output .= "</aree_tematiche>";     .......     file_put_contents("wp-content/uploads/cf7outputtest.xml", $  output); } 

Which is a really simple code. I’d like that if the user selects on the frontend a checkbox, his selection is displayed as a number and not with the entire string (as I’m doing now with the implode function). Furthermore if the user selects 2 checkboxes, I’d like that in the xml file the text is displayed as a loop like that, assuming that he has selected for instance checkbox 3 and 5:

<aree_tematiche>             begin of the loop  <area>                       first element of the loop, which shows checkbox n. 3 <macroarea></macroarea> <subarea>3</subarea>          </area>  <area>                       first element of the loop, which shows checkbox n. 5 <macroarea></macroarea> <subarea>5</subarea>          </area>  </aree_tematiche>            end of the loop 

So basically I want that based on my selection is displayed the selection integer number and not the string! Thanks, Luca