Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute:

I have this piece of code where I need to output some $_POST values into HTML. Nothing happens in the output line (see comment inside the code), even though var_dump() shows that the needed values are in the array and under the desired indexes.

The trick is that the array indexes for the required data depend on the counter $i. I'm feeling like there is some really stupid and basic syntax mistake in this code. Please help me, oh almighty Hivemind!

while ($i < $somespecificvar) 
{ 
    if (($i != 0) AND ($i < $somespecificvar)) 
    {
        echo "\n<td></td>\n";
    }

    echo "<td>";

    if ($_POST["text_l$i"] != 0)
    {
        echo "{$_POST['text_l$i']}, {$_POST['l$i']}";// NOTHING HAPPENS OVER HERE
    }

    echo "</td>";
    $i++;
}
share|improve this question

1 Answer 1

up vote 2 down vote accepted

In PHP, you can use the {$variable} inside a "" string, however it can only really handle basic variables. Change it so it's like so:

echo $_POST['text_l' . $i] . ', ' . $_POST['l' . $i];
share|improve this answer
    
Awesome! Thanks, man! I've spent days on trying to fix this one! – Rhiozan May 27 '13 at 15:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.