yo uso el siguiente fragmento de codigo
foreach ($_POST as $key => $value) {
${$key} = trim(addslashes(strip_tags($value)));
}
esto me genera variables con de forma automatica que utilizan el mismo name como nombre de variables.
si quiero imprimirlas por pantalla:
llamo a esta funcion:
$this->PrintVar();
que ejecuta este código:
function PrintVar() {
echo "Las variables que fueron enviadas vacias son rellenadas con '0' <br><br>";
echo '<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>Tipo</th>
<th>Nombre</th>
<th>Valor</th>
<th>Sobre Escrita</th>
</tr>
</thead>
<tbody>
';
$c = 0;
foreach ($_POST as $key => $value) {
${$key} = trim(addslashes(strip_tags($value)));
if (empty(${$key}) || ${$key} == NULL || ${$key} === '' || ${$key} === ' ') {
$value = 0;
${$key} = trim(addslashes(strip_tags($value)));
echo "<tr><td>" . gettype(${$key}) . "</td><td>" . print_r("$" . $key . "</td><td>|" . $value . "|</td><td>Sobre Escrita</td></tr>", TRUE);
} else {
echo "<tr><td>" . gettype(${$key}) . "</td><td>" . print_r("$" . $key . "</td><td>|" . $value . "|</td><td></td></tr>", TRUE);
}
$c++;
}
echo '</tbody></table></div>';
echo 'total de variables Computadas: ' . $c . '<br>';
}