Hi there, I'm trying to assign variables dynamically through a foreach loop, where I want to assign the value of a variable in an array to its own variable, something like this:
Obviously this doesn't work but I'm curious to know how you could achieve it.PHP Code:$fields = array("name","time","where","phone_no","job_description","quoted_price");
foreach($fields as $field)
{
if(empty($_POST['{$field}']))
{
die("You need to complete all fields.");
}
else
{
$ . $field = $field;
}
}
Like depending on the value in the array, assign that variable to itself. Of course I could get the same results in a different way but I like to make efficient code
I hope you can see what I mean...
Say "time" is being passed through:
$time = $field
Ok, well just ask me if you don't understand what I'm getting at.
Thanks,
Jack.




Reply With Quote

Bookmarks