432,369 Members | 1,001 Online
Need help? Post your question and get tips & solutions from a community of 432,369 IT Pros & Developers. It's quick & easy.

# Some strings are not true ?

 P: n/a This is true: "2-3"==1 But "1-2"==1 is not true Why ? Dec 31 '07 #1
5 Replies

 P: n/a gr*****@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_*************************@hotmail.com Jabber:iv*********@jabber.org ; iv*********@kdetalk.net Dec 31 '07 #2

 P: n/a On Dec 31, 1:24 pm, Iván Sánchez Ortega

 P: n/a gr*****@reenie.org wrote: This is true: "2-3"==1 But "1-2"==1 is not true Why ? 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 Dec 31 '07 #4

 P: n/a On Dec 31, 2:40 pm, Justin Koivisto 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. Dec 31 '07 #5

 P: n/a gr*****@reenie.org wrote: >This is true: "2-3"==1But "1-2"==1 is not trueWhy ? 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, ti**@probo.com Providenza & Boekelheide, Inc. Dec 31 '07 #6

### This discussion thread is closed

Replies have been disabled for this discussion.