Reply to Re: single quotes, double quotes and "undefined index"

Your name:

Reply:


Posted by Michael Fesser on 07/13/07 16:44

..oO(bill)

>I am trying to write clean code but keep having trouble deciding
>when to quote an array index and when not to.

Literal array indexs always have to be quoted, unless the entire array
is embedded in double-quoted string without using curly syntax:

print $foo['bar'];

print "hello $foo[bar]";

print "hello {$foo['bar']}";

All correct.

>sometimes when I quote an array index inside of double quotes I
>get an error about enased whitespace (to my best memory)
>
>AT other times I get an undefined index notice as below:
>
>Notice: Undefined index: last_reminder_id in...
>
>the 2nd line (which wraps to the 3rd in this posting
> is the one listed in the error message:
>
>$sql = "SELECT * from notes
>where recall_date > '0' and recall_date <= '$now' and id >
>'$_SESSION[last_reminder_id]'";

Syntax is correct. I'm just wondering why the values for the ID and date
fields are quoted. If a value is numeric, don't quote it. So the parser
might be right and the index is just not defined?

>what is the correct syntax and/or can anyone point me at a
>reference that will explain this ?

All possible syntax variants are explained in the manual (see the
examples).

Array do's and don'ts
http://www.php.net/manual/en/language.types.array.php#language.types.array.donts

Micha

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация