[PHP] setting the same value to multiple variables

2006-03-30 Thread charles stuart

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



Re: [PHP] setting the same value to multiple variables

2006-03-30 Thread Jasper Bryant-Greene

charles stuart wrote:

if ( 1 == 1 )


^^ what is the point of this?


{
$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\;

}


While this seems like excessively ugly code (have you considered an 
array? what is the point of all those variables if they all hold the 
same value?), replace all of those '' with '=' and you will be fine. 
PHP evaluates right-to-left and the result of an assignment is the value 
that was assigned, so that will work.


--
Jasper Bryant-Greene
General Manager
Album Limited

http://www.album.co.nz/ 0800 4 ALBUM
[EMAIL PROTECTED]  021 708 334

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] setting the same value to multiple variables

2006-03-30 Thread charles stuart

On Mar 30, 2006, at 11:01 PM, Jasper Bryant-Greene wrote:


charles stuart wrote:

if ( 1 == 1 )


^^ what is the point of this?



Just cutting out the long IF statement so everyone didn't have to  
look past it.



{
$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\;

}


While this seems like excessively ugly code (have you considered an  
array? what is the point of all those variables if they all hold  
the same value?), replace all of those '' with '=' and you will  
be fine. PHP evaluates right-to-left and the result of an  
assignment is the value that was assigned, so that will work.


Ah, I see. Thanks.

I place the variable in the label tag for each of the corresponding  
inputs (checkboxes in this case). If none are checked (at least one  
is required) I set an error message at the top of the page and then  
set a background color on each label via the now present  
class=errorHere.


I'm sure there's a better way to do this, but I'm not the best with  
PHP. I'll look into using an array.


Thanks again for your help. You've shortened my code at least a  
little bit.



best,

Charles

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php