I'm using variables as keys in an array. I understand that won't work with the superglobals. The following code snippet will run the correct number of times, but only picks up data on the first iteration. Do I have a variable variable syntax problem, or a loop problem? Can anyone clarify this for a newbie?
$php_postData = $_POST;
$php_totalPanels = $_SESSION['totalPanels'];
for ($php_count=1;$php_count<$php_totalPanels; $php_count++){
echo "<div class='individualQuote'>";
$php_currentItemWidth = 'width_' . $php_count;
$php_currentItemHeight = 'height_' . $php_count;
$php_currentItemDescription = 'description_' . $php_count;
$php_currentItemPartNumber = 'partNumber_' . $php_count;
$php_currentItemLexan = 'lexan_' . $php_count;
$php_currentItemVinyl = 'vinyl_' . $php_count;
$php_currentItemPolyester = 'polyester_' . $php_count;
if ( isset($php_postData[$php_currentItemDescription]) ){
echo "<p><span class='em'>Label Name: </span>" . $php_postData[$php_currentItemDescription] . "</p>";
}
if ( isset($php_postData[$php_currentItemPartNumber]) ){
echo "<p><span class='em'>Part Number: </span>" . $php_postData[$php_currentItemPartNumber] . "</p>";
}
if ( isset($php_postData[$php_currentItemLexan]) && $php_postData[$php_currentItemLexan] != '0' ) {
echo "<p><span class='em'>Material: </span>" . $php_postData[$php_currentItemLexan] . "</p>";
}
if ( isset($php_postData[$php_currentItemVinyl]) && $php_postData[$php_currentItemVinyl] != '0'){
echo "<p><span class='em'>Material: </span>" . $php_postData[$php_currentItemVinyl] . "</p>";
}
if ( isset($php_postData[$php_currentItemPolyester]) && $php_postData[$php_currentItemPolyester] != '0'){
echo "<p><span class='em'>Material: </span>" . $php_postData[$php_currentItemPolyester] . "</p>";
}
if ( isset($php_postData[$php_currentItemWidth]) && isset($php_postData[$php_currentItemHeight]) ){
echo "<p><span class='em'>Size: </span>" . $php_postData[$php_currentItemWidth] . " x " . $php_postData[$php_currentItemHeight] . "</p>";
}
echo "</div>";
}
"that won't work with the superglobals". What won't work with superglobals? Can you edit in the code you are using?session_start()so that$_SESSIONwill be available.$_POST[$something]works just fine. You've misunderstood that page. It's about "variable variables". You are not using that here. Variable variables is when you do this:$myVar = 6; $varName = 'myVar'; echo $$varName;. Notice the$$. That's a variable variable. What you are doing here is just accessing an array key with a variable, it's completely different.