|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44122 wrong return value for a key in function array_search
Submitted: 2008-02-14 20:06 UTC Modified: 2008-02-14 23:05 UTC
From: ron_tmp at roadrunner dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.2.5 OS: win32 (XP)
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: ron_tmp at roadrunner dot com
New email:
PHP Version: OS:


 [2008-02-14 20:06 UTC] ron_tmp at roadrunner dot com
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'.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2008-02-14 21:45 UTC]
Use the third parameter.
 [2008-02-14 23:05 UTC]
That 'strict' parameter is there for exactly this reason. Use it. :)
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Wed Jan 29 08:01:25 2020 UTC