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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: dan dot lugg at yahoo dot ca
New email:
PHP Version: OS:

 

 [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: Sat Apr 04 06:01:23 2020 UTC