At 22:40 08.03.2003, Khalid El-Kary said:
--------------------[snip]--------------------
>because you can't directly use the $annrow[id] within single quotes, you 
>should use double quotes to do so.
>
>file_exists("cherpdocs/$annrow[id].doc")
>
>or
>
>file_exists('cherpdocs/'.$annrow[id].'.doc')
>
>or
>
>file_exists("cherpdocs/".$annrow[id].".doc")
>
>Note: i heared it's prefered to always use the "." when including variables 
>within strings.
--------------------[snip]-------------------- 

Hmm - that's a bit different.

1) You can't use variables in singlequoted strings - these don't get parsed
by PHP.
2) You can absolutely use variables in doublequoted strings as these do get
parsed.
3) Array indices and object references must be enclosed in curly brackets
when used within double quotes to tell PHP what the variable and what the
string text is.
Example:
    "cherpdocs/$annrow[id].doc"  <== doesn't work correctly
    "cherpdocs/{$annrow['id']}.doc" <== will work
    "cherpdocs/$object->docname.doc" <== will not work
    "cherpdocs/{$object->docname}.doc" <== will work

Note that you should quote non-numeric array indices to allow PHP to
recognize it's not a defined value. Omitting quotes for index data would
trigger a warning (something like 'using unknown identifier id, assuming
"id"').


-- 
   >O     Ernest E. Vogelsinger
   (\)    ICQ #13394035
    ^     http://www.vogelsinger.at/



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

Reply via email to