Page 1 of 1

[solved]for loop

Posted: Sun Jan 18, 2004 2:24 pm
by vigge89
i've got the following code in my script;

Code: Select all

<?php
	for ($i = 1; $i <= 4; $i++) {
		if (empty ($_POST['entry_{$i}']) || $_POST['entry_{$i}'] == 'http://') { $_POST['entry_{$i}'] = "empty"; }; //If entry is empty
		$_POST['entry_{$i}'] = addslashes($_POST['entry_{$i}']); //Add slashes for security
	}
?>
but, of course i don't work. the $_POST['entry_{$i}'] apparently doesn't work very well. but now on to the question;
Is it possible to do this somehow? Becuase i don't really want to have 10 extra lines doing it when i just could use a loop....

Posted: Sun Jan 18, 2004 2:28 pm
by Fredix
I do believe it is because you use single quotes instead of normal double quotes. Try sth. like this:

Code: Select all

<?php
$_POST["entry_{$i}"] = "blabla";
?>

Posted: Sun Jan 18, 2004 2:30 pm
by vigge89
well, what can i say, it tried that at first, but i don't think i used them in all $_POST['entry_{$i}'], but now it seems to work, thanks! ;)