How to include php code inside the DELIMITER?

0

I need help, I would like to include a code inside the DELIMETER, but I can not, someone can help me or propose another alternative. The function below shows all the quantity I have in stock, a way for the customer to choose the quantity at the checkout!

Below is my code:

$product = <<<DELIMETER
 <a class="btn btn-default">
 <select id ="quantidade" name="quantidade"> <?PHP for ($i = 0; $i <=$row['produto_quantidade']; $i++) echo "<option value=".$i.">".$i."</option>";
 ?>  </select> </a>
DELIMETER;
    
asked by anonymous 06.04.2017 / 14:22

1 answer

2

heredoc is one multiline string, you must concatenate the results and add them as follows:

$options = "";

for ($i = 0; $i <=10; $i++) {
    $options .= "<option value='{$i}'>{$i}</option>";
}

$product = <<<DELIMETER
 <a class="btn btn-default">
 <select id ="quantidade" name="quantidade"> {$options}  </select> </a>
DELIMETER;

var_dump($product);

Output:

string(400) " <a class="btn btn-default">
 <select id ="quantidade" name="quantidade"> <option value='0'>0</option><option value='1'>1</option><option value='2'>2</option><option value='3'>3</option><option value='4'>4</option><option value='5'>5</option><option value='6'>6</option><option value='7'>7</option><option value='8'>8</option><option value='9'>9</option><option value='10'>10</option>  </select> </a>"

See in ideone

    
06.04.2017 / 14:38