When and when not to use ' and "

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I noticed today when I was using mysql_fetch_array something weird happened.

Database:
| id |
1

Code:
$colVal = "id";
$foo=mysql_fetch_array($someresult, MYSQL_ASSOC);

Now all I wanted to do was get the value of 1 into the variable $bar. Please
assume $someresult was the direct product of mysql_query("select * from
thistable");.

$bar = $foo['$colVal']; // didn't work
$bar = $foo['{$colVal}']; // didn't work
$bar = $foo[$colVal]; // worked
$bar = $foo['id']; // obviously worked

What I don't understand is why the first or second option didn't work.

Can anybody shed some light on this?

Brian Seymour
AeroCoreProductions
http://www.aerocore.net/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux