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
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Fri May 17 18:01:33 2024 UTC