3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $precio_1 = 100.00; $precio_2 = 150.00; $precio_3 = 231.50; $precio_4 = 458.44; $precio_5 = 123.15; for($i=1;$i<=5;$i++) { //Here I want to do the macrosustitution. $p = 'precio_'.$i; $precio = $$p; // use a named variable ?> <label>Precio <?php echo $i;?></label> <input type="text" name="<?php echo $precio; ?>" value="<?php echo $precio; ?>"/> <?php } ?>
Output for 4.3.0 - 7.1.0
<label>Precio 1</label> <input type="text" name="100" value="100"/> <label>Precio 2</label> <input type="text" name="150" value="150"/> <label>Precio 3</label> <input type="text" name="231.5" value="231.5"/> <label>Precio 4</label> <input type="text" name="458.44" value="458.44"/> <label>Precio 5</label> <input type="text" name="123.15" value="123.15"/>