Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: "Christoph M. Becker" Newsgroups: comp.lang.php Subject: Re: problem with double as array index? Date: Wed, 06 May 2015 22:57:43 +0200 Organization: solani.org Lines: 37 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Trace: solani.org 1430945858 12227 eJwNytEVwEAEBMCWHBZbTkL0X0Lud97A4kSnB8KxWHU+r8wqhujssTLuRz1ZWuAy7ZIsb5WxHxS2EGM= (6 May 2015 20:57:38 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Wed, 6 May 2015 20:57:38 +0000 (UTC) User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 X-User-ID: eJwFwQEBADAEBMBKDI84bPSPsDsTMK4rDGprq+/uCWHO0RFEbBIrN/qMRDmh8XJGpep40QcRlhDQ In-Reply-To: Cancel-Lock: sha1:NpJopmw1nnDdDIcADogAjTfpdC0= X-NNTP-Posting-Host: eJwFwQkBwDAIA0BLlBAeOS0M/xJ2R/jxDnO6cblSBX110XNGJm/M6PlA5GvEVREw0li7Ts0fFRcQdA== Xref: csiph.com comp.lang.php:15294 M. Strobel wrote: > I stumbled upon this problem when trying to define a trivalent logic: > > Interactive test: > > php > if (! define('triFalse',0)) trigger_error('Error defining!'); > php > if (! define('triMaybe',0.5)) trigger_error('Error defining!'); > php > if (! define('triTrue', 1)) trigger_error('Error defining!'); > php > > php > $triNotarray = array(triFalse=>triTrue, triMaybe=>triMaybe, > triTrue=>triFalse); > php > var_dump($triNotarray); > array(2) { > [0] => > double(0.5) > [1] => > int(0) > } > > Where is my Maybe value? You're triMaybe is there; triFalse is missing, however. > I was not aware of this problem (not coding PHP for some time), what is it? Firstly, a simplification: var_dump(array(0 => 'foo', 0.5 =>'foo', 1 => 'foo')); Explanation: when a float is used as array key, it is cast to int, see . So the second element overwrites the first element. -- Christoph M. Becker