Req #55229 [Opn->Bgs]: 0 is equal to false why not -1

From: Date: Mon, 18 Jul 2011 12:07:01 +0000
Subject: Req #55229 [Opn->Bgs]: 0 is equal to false why not -1
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-161960@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=55229&edit=1 ID: 55229 Updated by: pajoye@php.net Reported by: info at cdisun dot de Summary: 0 is equal to false why not -1 -Status: Open +Status: Bogus Type: Feature/Change Request Package: *General Issues Operating System: linux php PHP Version: Irrelevant Block user comment: N Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2011-07-18 08:00:35] 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 ?> ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=55229&edit=1

« previous php.bugs (#161960) next »