Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #15294
| From | "Christoph M. Becker" <cmbecker69@arcor.de> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: problem with double as array index? |
| Date | 2015-05-06 22:57 +0200 |
| Organization | solani.org |
| Message-ID | <midv82$bu3$1@solani.org> (permalink) |
| References | <midt9v$ihf$1@dont-email.me> |
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 | Next — Previous in thread | Next in thread | Find similar | Unroll 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