Bug #64616 [Opn->Nab]: bug
| From: | nikic@php.net | Date: | Tue, 09 Apr 2013 18:11:11 +0000 |
| Subject: | Bug #64616 [Opn->Nab]: bug | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-178379@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=64616&edit=1
ID: 64616
Updated by: nikic@php.net
Reported by: spawnm at spawnm dot pl
Summary: bug
-Status: Open
+Status: Not a bug
Type: Bug
Package: Arrays related
Operating System: ubuntu 12.10
PHP Version: 5.4Git-2013-04-09 (Git)
Block user comment: N
Private report: N
New Comment:
By default in_array uses == comparison (and true == 'lol'). If you want to use strict ===
comparison pass "true" as an additional parameter:
in_array('lol', $arr, true);
Previous Comments:
------------------------------------------------------------------------
[2013-04-09 16:18:56] spawnm at spawnm dot pl
Description:
------------
PHP Version: 5.4.6-1ubuntu1.2
$arr = array ( 'error' => true );
echo in_array('lol', $arr)? 1: 0;//1
$arr = array ( 'error' => 'true' );
echo in_array('lol', $arr)? 1: 0;//0
Test script:
---------------
$arr = array ( 'error' => true );
echo in_array('lol', $arr)? 1: 0;//1
$arr = array ( 'error' => 'true' );
echo in_array('lol', $arr)? 1: 0;//0
Expected result:
----------------
$arr = array ( 'error' => true );
echo in_array('lol', $arr)? 1: 0;//1
$arr = array ( 'error' => 'true' );
echo in_array('lol', $arr)? 1: 0;//0
Actual result:
--------------
$arr = array ( 'error' => true );
echo in_array('lol', $arr)? 1: 0;//1
$arr = array ( 'error' => 'true' );
echo in_array('lol', $arr)? 1: 0;//0
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=64616&edit=1