php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #52214 Using ampersand not percent for modulus.
Submitted: 2010-07-01 00:23 UTC Modified: 2010-07-01 00:35 UTC
From: dan dot lugg at yahoo dot ca Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: 5.3.2 OS:
Private report: No CVE-ID: None
 [2010-07-01 00:23 UTC] dan dot lugg at yahoo dot ca
Description:
------------
It appears that an example in the documentation for array_filter() is performing modulus with an ampersand (&) not percent (%) as it should.

function odd($arg){
   return($arg & 1); // should be return ($arg % 1);
}


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-07-01 00:35 UTC] degeberg@php.net
-Status: Open +Status: Bogus
 [2010-07-01 00:35 UTC] degeberg@php.net
It's not trying to do modular arithmetic. & is "bitwise and", and the function checks if the last bit is 1, i.e. if it is odd. The example is correct.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Wed Nov 25 00:01:23 2020 UTC