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

Reply via email to