Re: [PHP] why is (intval('444-44444') == '444-44444') EQUAL??!
Using == will compare the two values after type juggling is performed. === will compare based on value and type (identical). PHP Will type juggle the string to an integer. Your if/else is just like saying: php> if (444 == "444") echo 'equal'; else echo 'not equal'; equal -- Mike Mackintosh PHP 5.3 ZCE On Thursday, June 21, 2012 at 10:27 PM, Daevid Vincent wrote: > Huh? Why is this equal??! > > php > $id = '444-4'; > > php > var_dump($id, intval($id)); > string(9) "444-4" > int(444) > > php > if (intval($id) == $id) echo 'equal'; else echo 'not equal'; > equal > > or in other words: > > php > if (intval('444-4') == '444-4') echo 'equal'; else > echo 'not equal'; > equal > > I would expect PHP to be evaluating string "444-4" against integer "444" > (or string either way) > > however, just for giggles, using === works... > > php > if ($id === intval($id)) echo 'equal'; else echo 'not equal'; > not equal > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >
Re: [PHP] why is (intval('444-44444') == '444-44444') EQUAL??!
On 12-06-21 10:27 PM, Daevid Vincent wrote: Huh? Why is this equal??! php> $id = '444-4'; php> var_dump($id, intval($id)); string(9) "444-4" int(444) php> if (intval($id) == $id) echo 'equal'; else echo 'not equal'; equal or in other words: php> if (intval('444-4') == '444-4') echo 'equal'; else echo 'not equal'; equal I would expect PHP to be evaluating string "444-4" against integer "444" (or string either way) however, just for giggles, using === works... php> if ($id === intval($id)) echo 'equal'; else echo 'not equal'; not equal Using === will always fail because on the left you have a string and on the right you have an integer which fails exact comparison based on datatype mismatch. When comparing a string to an integer using == PHP performs type juggling and converts the string to an integer first. Cheers, Rob. -- E-Mail Disclaimer: Information contained in this message and any attached documents is considered confidential and legally protected. This message is intended solely for the addressee(s). Disclosure, copying, and distribution are prohibited unless authorized. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] why is (intval('444-44444') == '444-44444') EQUAL??!
Huh? Why is this equal??! php > $id = '444-4'; php > var_dump($id, intval($id)); string(9) "444-4" int(444) php > if (intval($id) == $id) echo 'equal'; else echo 'not equal'; equal or in other words: php > if (intval('444-4') == '444-4') echo 'equal'; else echo 'not equal'; equal I would expect PHP to be evaluating string "444-4" against integer "444" (or string either way) however, just for giggles, using === works... php > if ($id === intval($id)) echo 'equal'; else echo 'not equal'; not equal -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Variable representation
or you can do this echo $row["Bible_knowledge_phrase_solver_game_question_topics_$i"];
RE: [PHP] Variable representation
-Original Message- From: Ron Piggott [mailto:ron.pigg...@actsministries.org] Sent: Thursday, June 21, 2012 3:47 AM To: php-general@lists.php.net Subject: [PHP] Variable representation I am trying to represent the variable: $row['Bible_knowledge_phrase_solver_game_question_topics_1'] Where the # 1 is replaced by a variable --- $i The following code executes without an error, but “Hello world” doesn’t show on the screen. What needs to change? Ron Ron Piggott www.TheVerseOfTheDay.info You can do this echo $row['Bible_knowledge_phrase_solver_game_question_topics_'.$i]; I would not suggest a variable name that long. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Variable representation
I am trying to represent the variable: $row['Bible_knowledge_phrase_solver_game_question_topics_1'] Where the # 1 is replaced by a variable --- $i The following code executes without an error, but “Hello world” doesn’t show on the screen. What needs to change? Ron Ron Piggott www.TheVerseOfTheDay.info