|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2009-07-15 12:12 UTC] jani@php.net
[2009-07-23 01:00 UTC] php-bugs at lists dot php dot net
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 19:00:01 2025 UTC |
Description: ------------ I have a function which is used to assign values into a number of global arrays. Two of the arrays are assigned values that are generated using the rand() function. A third array holds the result of the multiplication. When both first two arrays are assigned a value of 0 (zero), the result of the multiplication is 1 and not 0. This information is then entered into a html form and presented to the user and they are asked to enter the results of $numfacttest[$a] / $randval[$a] = useranswer The useranswer is then compared to $answer[$a] which is already calculated. The problem is that 0 * 0 is returning the answer 1 sometimes. Reproduce code: --------------- function setnumberfacttest($count,$maxnumberfacts) { global $numfacttest, $answer, $operator, $randval; for ($a=0 ; $a < $count ; $a++) { $operator[a]=chr(247); $bit1=rand(0,$maxnumberfacts); $bit2=rand(0,$maxnumberfacts); $numfacttest[$a]=$bit1 * $bit2; $randval[$a]=$bit2; $answer[$a]=$bit1; } } Expected result: ---------------- Actual Results with hidden value displayed 2 / 1 = <useranswer> 2 0 / 0 = <useranswer> 0 0 / 0 = <useranswer> 0 2 / 2 = <useranswer> 1 4 / 2 = <useranswer> 2 1 / 1 = <useranswer> 1 0 / 0 = <useranswer> 0 0 / 0 = <useranswer> 0 0 / 0 = <useranswer> 0 1 / 1 = <useranswer> 1 Actual result: -------------- Actual Results with calculated hidden value displayed 2 / 1 = <useranswer> 2 0 / 0 = <useranswer> 1 0 / 0 = <useranswer> 0 2 / 2 = <useranswer> 1 4 / 2 = <useranswer> 2 1 / 1 = <useranswer> 1 0 / 0 = <useranswer> 1 0 / 0 = <useranswer> 0 0 / 0 = <useranswer> 2 1 / 1 = <useranswer> 1