Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #15294

Re: problem with double as array index?

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" <cmbecker69@arcor.de>
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 <midv82$bu3$1@solani.org> (permalink)
References <midt9v$ihf$1@dont-email.me>
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 <midt9v$ihf$1@dont-email.me>
Cancel-Lock sha1:NpJopmw1nnDdDIcADogAjTfpdC0=
X-NNTP-Posting-Host eJwFwQkBwDAIA0BLlBAeOS0M/xJ2R/jxDnO6cblSBX110XNGJm/M6PlA5GvEVREw0li7Ts0fFRcQdA==
Xref csiph.com comp.lang.php:15294

Show key headers only | View raw


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
<http://php.net/manual/en/language.types.array.php#language.types.array.syntax>.
 So the second element overwrites the first element.

-- 
Christoph M. Becker

Back to comp.lang.php | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

problem with double as array index? "M. Strobel" <strobel@example.com> - 2015-05-06 22:25 +0200
  Re: problem with double as array index? "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-05-06 22:57 +0200
  Re: problem with double as array index? adam <adam@nospam.net> - 2015-05-06 21:12 +0000
    Re: problem with double as array index? "M. Strobel" <strobel@example.com> - 2015-05-07 00:45 +0200
      Re: problem with double as array index? "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-05-07 01:08 +0200
        Re: problem with double as array index? "M. Strobel" <strobel@example.com> - 2015-05-07 13:36 +0200

csiph-web