I wrote this function in PHP. It divides each variable \$votesX, where X is a politic party name, for 1,2,3... to the value of \$seats. Now I've to search the the biggest values of the array and replace them with a zero. How can I do it?

``````function hondt (\$votesA,\$votesB,\$votesC,\$votesD,\$votesE,\$seats){
for (\$i=1; \$i<=\$seats; \$i++){
}
for (\$i=1; \$i<=\$seats; \$i++){
}
for (\$i=1; \$i<=\$seats; \$i++){
}
for (\$i=1; \$i<=\$seats; \$i++){
}
for (\$i=1; \$i<=\$seats; \$i++){
}
}``````

I need it urgently.

Thank you in advance.

## All 8 Replies

Now I've to search the the biggest values of the array and replace them with a zero. How can I do it???

Can you give one example with live values?

I think you can do the following:

``````function hondt (\$votesA,\$votesB,\$votesC,\$votesD,\$votesE,\$seats)
{
for (\$i=1; \$i<=\$seats; \$i++)
{
}
for (\$i=1; \$i<=\$seats; \$i++)
{
}
for (\$i=1; \$i<=\$seats; \$i++)
{
}
for (\$i=1; \$i<=\$seats; \$i++)
{
}
for (\$i=1; \$i<=\$seats; \$i++)
{
}
for (\$n=0; \$n <= 4; \$n++)
{
}
}``````

And I think that the following code will do the best briefly:

``````function hondt (\$votesA,\$votesB,\$votesC,\$votesD,\$votesE,\$seats)
{
for(\$ii=0; \$ii <= 5; \$ii++)
{
for (\$i=1; \$i<=\$seats; \$i++)
{
}
}
for (\$i=0; \$i <= 4; \$i++)
{
}
}``````

Wish it's done what you want. :)

you need to define \$votes as an array
like

``\$votes = array();``

you need to define \$votes as an array

You can try it.. It works perfectly fine (100%) without defining it as an array...
PHP is an easy language that doesn't oblige you to type every single detail (With no excess).

okay i allways define everything then later i dont get any problem

make it work make it nice make it fast

And this is how to make it fast! :)

yh okay but first tings are gonna work

I tried this code and it worked perfectly. Has it worked perfectly with you, vibhadebit?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.