Concatenate in PHP [duplicate]

1

Good morning, I'm starting PHP programming and today we have sent a simple little exercise to practice. What asks us is that the two echo are exactly the same, but in the first echo of the variable $sql if I show '2DAW' with the single quotes and in the other echo in which I concatenate the variable $aula shows me without single quotes.

<?php
    echo "<h3>SIN VARIABLE</h3>";
    $sql = "select * <br>
            from alumnos <br>
            where clase = '2DAW'";
    echo $sql;
    echo '<br><br>';

    echo "<h3>CON VARIABLE</h3>";
    $aula = "2DAW";
    $sql = "select * <br>
            from alumnos <br>
            where clase = ".$aula;
    echo $sql;
    echo '<br><br>';
  ?>
    
asked by Mario Guiber 20.09.2017 в 19:01
source

1 answer

3

the quotes in $aula = "2DAW"; denote that it is text, but are not part of the string as such, if you want the quotes to appear you have to put them in the text $aula = "'2DAW'";

    
answered by 20.09.2017 / 19:04
source