bradgrafelman wrote:Not to mention:
Array indeces in your case should be strings. $row[name] does not have a string as an index, but a constant. PHP will detect this (assuming there actually isn't a constant named 'name') and throw an E_WARNING and then assume it is a string. So, use quotes: $row['name'].
Arrays, more specifically items in arrays referenced by indeces, should not simply appear inside a double-quoted string. If they do, they should be wrapped in braces ( {} ). Instead, I usually escape out of the string and concatenate the array in the middle, like so:
echo 'Your name is: ' . $row['name'] . '! Hello there.';
I agree with brad's recommendations.
However, although associative array keys SHOULD indeed be used as $row['somekey'] you'll find that this works:
$row = array('somevar'=>'foo','anothervar'=>'bar');
$test = "$row[somevar]$row[anothervar]" ;
echo $test; // will output 'foobar'
It's a common misconception because $row[somvar] will fail if not wrapped in double quotes - the double quotes will parse this as valid.
Although this works, you should do it as brad has suggested.
regards,