Jump to content

Initializing lots of numeric variables to 0 -- best way to code?


mrherman

Recommended Posts

Oh, sorry, I was using $var as an example...The actual variables have names of different length, such as...

 

$totalcorrect

$totalitems

$pctcorrect

$appcount

 

I was wondering if you can do something like (although I know this will not work):

 

Store 0 to $totalcorrect, $totalcnt, $....... ;

 

The only way to do that would be to make an array which stores the variable names.

 

<?php
$var_name = array('totalcorrect', 'totalitems', 'pctcorrect', 'appcount');

foreach ($var_name as $name) {
  ${$name} = 0;
}
?>

 

So this still involves a bit of manual work.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.