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
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
You are using the wrong quotes:
echo "<input type=\"number\" name=\"$num[$i]\">";
Variables inside a single quoted string are not parsed.
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>";
?>
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.