php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42131 in_array return 0 value when there's no specified 0 value in array
Submitted: 2007-07-28 11:58 UTC Modified: 2007-07-28 12:53 UTC
From: mitch dot pascual at phpugph dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.2.3 OS: Windows XP
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: mitch dot pascual at phpugph dot com
New email:
PHP Version: OS:

 

 [2007-07-28 11:58 UTC] mitch dot pascual at phpugph dot com
Description:
------------
return 0 value when there's no specified 0 value in array

Reproduce code:
---------------
    <?php
    $array1 = array(?php?, ?java?, ?ruby?, ?asp?);
    $array2 = array(?php? => ?PHP.net?, ?java? => ?java.com?, 0 => ?javascript?, 1 => ?actionscript?);

    foreach ($array2 as $key => $value) {
    if ( in_array($key, $array1) ) {
    print ?in array: $key <br />?;
    } else {
    print ?not in array: $key <br />?;
    } # end if

    } # end foreach

    ?>

Expected result:
----------------
in array: php
in array: java
not in array: 0
not in array: 1

Actual result:
--------------
in array: php
in array: java
in array: 0
not in array: 1

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-07-28 12:26 UTC] johannes@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

.
 [2007-07-28 12:53 UTC] mitch dot pascual at phpugph dot com
Hi,

On the code I provided, how come that there's a value 0 on the array ($array1)? Can you please explain it further?

Thanks a lot!
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 17:01:33 2025 UTC