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
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.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 09:01:26 2024 UTC