Some strings are not true ?

Some strings are not true ?

am 31.12.2007 19:15:22 von meltedown

This is true: "2-3"==1

But "1-2"==1 is not true

Why ?

Re: Some strings are not true ?

am 31.12.2007 19:24:29 von ivansanchez-alg

groups2@reenie.org wrote:

> This is true: "2-3"==1
>
> But "1-2"==1 is not true
>
> Why ?

RTFM on type juggling. You may not be doing a comparison between integers or
between strings. Force type casting where appropiate.

--
----------------------------------
Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

MSN:i_eat_s_p_a_m_for_breakfast@hotmail.com
Jabber:ivansanchez@jabber.org ; ivansanchez@kdetalk.net

Re: Some strings are not true ?

am 31.12.2007 19:52:08 von meltedown

On Dec 31, 1:24 pm, Iv=E1n S=E1nchez Ortega escomposlinux.-.punto.-.org> wrote:
> grou...@reenie.org wrote:
> > This is true: "2-3"==1
>
> > But "1-2"==1 is not true
>
> > Why ?
>
> RTFM on type juggling. You may not be doing a comparison between integers =
or
> between strings. Force type casting where appropiate.
>
> --
> ----------------------------------
> Iv=E1n S=E1nchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-
>
> MSN:i_eat_s_p_a_m_for_breakf...@hotmail.com
> Jabber:ivansanc...@jabber.org ; ivansanc...@kdetalk.net

Yes, I read that already. I know how to make it consistent with type
casting, but that is not my question.

In both cases, it is a comparison between a string and an integer.

The Manual says:
If the string starts with valid numeric data, this will be the value
used. Otherwise, the value will be 0 (zero).

Bot strings start with valid numeric data, so I still want to know why
one is true and the other is not.

Re: Some strings are not true ?

am 31.12.2007 20:40:11 von Justin Koivisto

groups2@reenie.org wrote:
> This is true: "2-3"==1
>
> But "1-2"==1 is not true
>
> Why ?
>

var_dump("2-3"==1);
var_dump("1-2"==1);
?>
Output:
bool(false)
bool(true)

Why? "2-3" evaluates to 2, "1-2" evaluates to 1. 2!=1 therefore the
first statement is false, the second one is true because 1==1

--
Posted via a free Usenet account from http://www.teranews.com

Re: Some strings are not true ?

am 31.12.2007 21:55:38 von meltedown

On Dec 31, 2:40 pm, Justin Koivisto wrote:
> grou...@reenie.org wrote:
> > This is true: "2-3"==1
>
> > But "1-2"==1 is not true
>
> > Why ?
>
> > var_dump("2-3"==1);
> var_dump("1-2"==1);
> ?>
> Output:
> bool(false)
> bool(true)
>
> Why? "2-3" evaluates to 2, "1-2" evaluates to 1. 2!=1 therefore the
> first statement is false, the second one is true because 1==1
>
> --
> Posted via a free Usenet account fromhttp://www.teranews.com

OK, thanks, it makes sense now.

Re: Some strings are not true ?

am 31.12.2007 22:53:16 von Tim Roberts

groups2@reenie.org wrote:
>
>This is true: "2-3"==1
>
>But "1-2"==1 is not true
>
>Why ?

I get exactly the opposite results with the antique PHP 4.1.2 on my Linux
system.

What's happening here is that PHP tries to convert the string to an integer
for the comparison, and that conversion stops at the first non-digit (the
"-").

So, converting "2-3" produces the integer 2, and converting "1-2" produces
the integer 1.
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.