This seems like a simple question to ask, but is it usually a good idea to reuse variables in any scripting language?
I am particularly interested in the reasons why this is / is not good practice, since I am apart from myself if I should or should not do this.
For example, it $iis one of the most common variables used in a loop to iterate through things.
For example (in php):
$i=0;
foreach ($array as $v) {
$i++;
if ($i<count($array))
{
echo $v.', ';
}
else {
echo $v;
}
}
Let's say I had several loops in my script, it would be better to reuse $ior just use another variable, such as $a, and for any other loops - from $bto $z.
, $i, $i=0; null , script. , .
, ?
$i=0; //Recycling $i
, , , script , , ?
, , , , ?
, , , , , .