Is it possible to generate variable names from array or list to avoid repetition? I am pulling item values from html form, this is the excerpt of code:
$item1 = $item2 = $item3 = $item4 = "";
if (isset($_GET["submit"])) {
if (!empty($_GET["item1"])) { $item1 = htmlentities($_GET["item1"]);} else { $item1="*"; }
if (!empty($_GET["item2"])) { $item2 = htmlentities($_GET["item2"]);} else { $item2="*"; }
if (!empty($_GET["item3"])) { $item3 = htmlentities($_GET["item3"]);} else { $item3="*"; }
if (!empty($_GET["item4"])) { $item4 = htmlentities($_GET["item4"]);} else { $item4="*"; }
}
Would it be possible to make array of items and generate the if block with foreach ?