A scripting newbie question... I'm trying to understand some code I found.
This script conducts a poll and writes the results to a text file. The
following statement is part of the source file. The exact code is not important
to my question so don't wrack your brain on this.
if (isset($votingstep)) {
function ShowTheStuff($item, $itemvoted, $graph_width, $graph_height) {
$hector=count($itemvoted);$totalvotes=0;$in=0;$ste pstr='';
$totalvotes=SumArray($itemvoted);
$in=0;
if ($totalvotes==0) { $totalvotes=0.0001; }
while ($in<$hector) {
$stepstr=$stepstr.stripslashes($item[$in]).':
'.(int)(($itemvoted[$in]/$totalvotes)*100).'%<br>';
$timesred=(int)((($itemvoted[$in]/$totalvotes))*$graph_width);
$stepstr=$stepstr.'<img height='.$graph_height.'
width='.$timesred.' src="lp_1.gif"><img
height='.$graph_height.' width='.($graph_width-$timesred).'
src="lp_0.gif"><br><br>';
$in++;
}
return $stepstr;
}
}
My question is this. A function is contained with an 'if' statement. How does
this work? I've never seen this before in any non-scripting language. This
function 'ShowTheStuff' is called further down in the file.
In the flow of the program as it falls thru line by line, if it meets the 'if'
condition then it hits the function, which it can't call because it doesn't have
the parameters. What's the point?
Further along in the program when the 'ShowTheStuff' function gets called, how
is it able to call it when it's another block of code (the 'if' block)? Or is
it able to call it but it must meet the 'if' condition?
This makes no sense to me. What is the flow of execution here?
Thanks for your help.