php-general Digest 22 Jun 2012 02:27:35 -0000 Issue 7863
Topics (messages 318282 through 318284):
Re: Variable representation
318282 by: admin
318283 by: As'ad Djamalilleil
why is (intval('444-44444') == '444-44444') EQUAL??!
318284 by: Daevid Vincent
Administrivia:
To subscribe to the digest, e-mail:
php-general-digest-subscr...@lists.php.net
To unsubscribe from the digest, e-mail:
php-general-digest-unsubscr...@lists.php.net
To post to the list, e-mail:
php-gene...@lists.php.net
----------------------------------------------------------------------
--- Begin Message ---
-----Original Message-----
From: Ron Piggott [mailto:ron.pigg...@actsministries.org]
Sent: Thursday, June 21, 2012 3:47 AM
To: php-gene...@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.
<?php
$row['Bible_knowledge_phrase_solver_game_question_topics_1'] = "hello world";
$i = 1;
echo ${"row['Bible_knowledge_phrase_solver_game_question_topics_$i']"};
?>
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.
--- End Message ---
--- Begin Message ---
or you can do this
echo $row["Bible_knowledge_phrase_solver_game_question_topics_$i"];
--- End Message ---
--- Begin Message ---
Huh? Why is this equal??!
php > $id = '444-44444';
php > var_dump($id, intval($id));
string(9) "444-44444"
int(444)
php > if (intval($id) == $id) echo 'equal'; else echo 'not equal';
equal
or in other words:
php > if (intval('444-44444') == '444-44444') echo 'equal'; else
echo 'not equal';
equal
I would expect PHP to be evaluating string "444-44444" 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
--- End Message ---