Is it possible to get a variable name and use it as a string?

1

Is it possible to get a variable name and use it as a string? Situation: I have a form full of inputs when I send the pass with your name and value right, but I need to also update them in the DB using its correct id to insert, in the input the value is used to pass urls. so I was thinking of giving the id in the name then getting Array( "id_1"=>"http://exemplo.com") . But I need the ID to insert into the correct DB line.

          <?php
        for ($i = 0; $i < $nomeDasTabelas['value']; $i ++) {
            $aux = $i + 1;
            echo '<div class="object">
                <form method="GET" action="index.php">
                <div class="grade">
                    <input type="hidden" name="serie" value="'.$aboutSerie[0].'">';

            for ($is = 0; $is < $valorDeLinks[$i]; $is ++) {
                $auxs = $is + 1;
                $tabelaDeIds = $idDosLinks[$i];
                $idDoLink = $tabelaDeIds[$is];
                $btndel = '&btn=btndel&tab=' . $nomeDasTabelas[$i] . '&id=' . $idDoLink;

                echo ($is % 4 == 0) ? '<br>' : "";
                echo '<label for="txtboxtp' . $aux . 'ep' . $auxs . '">Ep' . $auxs . '|</label>
                    <input id="txtboxtp' . $aux . 'ep' . $auxs . '" type="text" class="textbox" name="' . $is . '" value="http://">
                    <a href="index.php?serie=' . $aboutSerie[0] . $btndel . '"><button class="btndel" type="button" name="btndel" title="Excluir"><img src="../imgsys/icon_del.png" alt="Del" title="Excluir"></button></a>
                    <input type="hidden" name="ep'.$is.'" value="'.$idDoLink.'">';    
            }
    
asked by anonymous 13.06.2016 / 04:13

1 answer

1

I do not understand the question very well, so I go for the title:

Is it possible to get a variable name and use it as a string?

Yes, it is possible, the easiest method to do this is by exploring the syntax of PHP , where when using a string with a quotation mark it does not recognize the variable as variable but rather as a string normal, so I use a little 'gambiarra'. An example:

<?php
    $minhaVariavel = "Stack Overflow";
    $nomeVariavel = '$minhaVariavel';
    $nomeVariavel = mb_substr($nomeVariavel, 1); // tira o $ do nome da variavel

    echo "Nome: ".$nomeVariavel."<br/>";
    echo "Valor: ".$minhaVariavel;

The output will be:

Nome: minhaVariavel
Valor: Stack Overflow

I repeat again that I did not quite understand the question, I voted to close because it is not clear, so I was only for the title. If that is not the purpose of the question then I withdraw my answer and ask you to edit the question so we can understand the question.

    
18.06.2016 / 23:59