how to use php variable as a html variable?

<?php
$num=array();
for($i=0;$i<5;$i++)
echo '<input type="number" name="$num[$i]">';
?>

i need to display the inputted number in the array.
it's not working. please help

Recommended Answers

All 4 Replies

Member Avatar for diafol

Will the array var item be parsed like that? Thought you needed a brace.

Try this:

 <?php
    $num=array(rand(), rand(), rand(), rand(), rand());
    for($i=0;$i<5;$i++)
    echo '<input type="number" value="'.$num[$i].'">';
    ?>

Your array is empty

try this code it will work
<?php
for($i=0;$i<5;$i++)

$num = array($i);
echo '<input type="number" name="'.$num[0].'"/>';
echo "<br>";

?>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.