470,833 Members | 1,190 Online

# Turning this into a function (Beginner Level)

I need some help writing the following lines of code into a simple
function. I'd like to be able to create a function to do the
calculation, then feed the \$a, \$b, or \$c variable into it.

Thanks,
J

\$kpercentage = \$a * 100;
\$kpercent = round(\$kpercentage, 0);
?>

\$bpercentage = \$b * 100;
\$bpercent = round(\$bpercentage, 0);
?>
\$npercentage = \$c * 100;
\$npercent = round(\$npercentage, 0);
?>
Jul 17 '05 #1
3 1405
Jason wrote:
[snip]

return \$total;
}

Use example:
echo 'Kerry has yer '.votepercent(\$quantityforkerry, \$totalofvotes).' %

Aphrael...
--
"La demande mondiale d’ordinateurs n’excédera pas cinq machines."
(Thomas Watson, Fondateur d'IBM, 1945)
Jul 17 '05 #2
Jason wrote:
I need some help writing the following lines of code into a simple
function. I'd like to be able to create a function to do the
calculation, then feed the \$a, \$b, or \$c variable into it.

[snip]

You needn't do it one by one ...
Here's a function to do it all in one swoop :-)
<?php
\$ret[\$k] = round(\$v/\$sum*100);
}
return \$ret;
}

/* example usage */

/* disclaimer: the numbers are random */

print_r(\$percs);
?>

--
USENET would be a better place if everybody read: | to mail me: simply |
http://www.catb.org/~esr/faqs/smart-questions.html | "reply" to this post, |
http://www.netmeister.org/news/learn2quote2.html | *NO* MIME, plain text |
http://www.expita.com/nomime.html | and *NO* attachments. |
Jul 17 '05 #3
thanks, this looks good.. i'll try both methods..
Jul 17 '05 #4

### This discussion thread is closed

Replies have been disabled for this discussion.