From:             ron_tmp at roadrunner dot com
Operating system: win32 (XP)
PHP version:      5.2.5
PHP Bug Type:     Arrays related
Bug description:  wrong return value for a key in function array_search 

Description:
------------
I trying to get the fraction part of a decimal number using the string
keys of an array as a lookup table.

Example: 4.25 -> 4-1/4

I sending argument 25 to function 'ConvToFrac'
and getting the corresponding key value ('1/4' for this case).





Reproduce code:
---------------
 echo ConvToFrac('0625');

 function ConvToFrac($value) {
   $frac_conv =
array('1/2'=>'5','1/4'=>'25','3/4'=>'75','1/8'=>'125','3/8'=>'375','5/8' =>
'625',
    '7/8'=>'875','1/16' =>
'0625','3/16'=>'1875','5/16'=>'3125','7/16'=>'4375','9/16'=>'5625','11/16'
=>'6825',
    '13/16' =>'8125','15/16'=>'9375');

  $key = array_search($value, $frac_conv);
  return $key;
 }

Expected result:
----------------
I expecting '1/16' for argument '0625'
 


Actual result:
--------------
I'm getting '5/8'

the search can not differentiate between array string key '625' and
'0625'.
 

-- 
Edit bug report at http://bugs.php.net/?id=44122&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=44122&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=44122&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): 
http://bugs.php.net/fix.php?id=44122&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=44122&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=44122&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=44122&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=44122&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=44122&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=44122&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=44122&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=44122&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=44122&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=44122&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=44122&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=44122&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=44122&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=44122&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=44122&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=44122&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=44122&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=44122&r=mysqlcfg

Reply via email to