php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #55229 0 is equal to false why not -1
Submitted: 2011-07-18 08:00 UTC Modified: 2011-07-18 08:07 UTC
From: info at cdisun dot de Assigned:
Status: Not a bug Package: *General Issues
PHP Version: Irrelevant OS: linux php
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: info at cdisun dot de
New email:
PHP Version: OS:

 

 [2011-07-18 08:00 UTC] info at cdisun dot de
Description:
------------
---
From manual page: http://www.php.net/function.array-search%23Changelog
---
array_search gives the result of false when nothing will be found , that is equal to  index 0, why not -1.
-1 means like in javascript , nothing is found.
0 would than be a correkt index found number.



Test script:
---------------
<?php
$array = array(0 => 'blau', 1 => 'rot', 2 => 'grün', 3 => 'rot');

$key = array_search('grün', $array);  // $key = 2;
$key = array_search('rot', $array);   // $key = 1;
$key = array_search('yello', $array);   // $key = 0; 0 is equal to false

$key = isset( $array[$key] ) ? $key : -1 ; // this solve that 0/false to -1

?> 



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-07-18 08:07 UTC] pajoye@php.net
-Status: Open +Status: Bogus
 [2011-07-18 08:07 UTC] pajoye@php.net
It cannot be changed without breaking every application out there. While I do not 
follow your reasoning here either. False is used in many other functions.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Nov 26 02:00:01 2025 UTC