You could use variable variables with an array, like this:
$arr =
array('readingGoalsEnjoymentLabelClass','readingGoalsInformationLabelClass',
'readingGoalsAlphabeticLabelClass','readingGoalsPrintLabelClass',
'readingGoalsPhonologicalLabelClass','readingGoalsPhoneticLabelClass',
'readingGoalsComprehensionLabelClass','readingGoalsVocabularyLabelClass',
'readingGoalsInstructionsLabelClass','readingGoalsCriticalLabelClass',
'readingGoalsCommunicateLabelClass');
foreach ($arr as $var) {
${$var} = 'class="errorHere"';
}
/* This is to check if it was done correctly. */
foreach ($arr as $var) {
echo "$var = ${$var}\n";
}
charles stuart escribió:
Hi,
I'm sure this is quite basic. Nonetheless I'm new to PHP so I haven't
figured it out.
I'd like to set each variable to the same value (without having to set
that value individually for each variable).
Thanks for the help.
best,
Charles
if ( 1 == 1 )
{
$goodToGo = 0; $errorArray[] = "You must declare some goals on
Activity 1.";
// this block of code does not set each variable to "class=\"errorHere\"";
$readingGoalsEnjoymentLabelClass &&
$readingGoalsInformationLabelClass &&
$readingGoalsAlphabeticLabelClass &&
$readingGoalsPrintLabelClass &&
$readingGoalsPhonologicalLabelClass &&
$readingGoalsPhoneticLabelClass &&
$readingGoalsComprehensionLabelClass &&
$readingGoalsVocabularyLabelClass &&
$readingGoalsInstructionsLabelClass &&
$readingGoalsCriticalLabelClass &&
$readingGoalsCommunicateLabelClass = "class=\"errorHere\"";
}
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php