You are here: Re: Undefined offset- how to prevent warning message? « All PHP « IT news, forums, messages
Re: Undefined offset- how to prevent warning message?

Posted by Tom Peel on 09/28/42 11:41

Erlend Klakegg Bergheim wrote:
> Tom Peel skrev:
>
>> Good Man wrote:
>>
>>> Tom Peel <notreallytandp@freenet.de> wrote in
>>> news:46qs8bFcjg1qU1@individual.net:
>>>
>>>> This is pretty ugly, because I cannot predict the final size of the
>>>> array.
>>>> Is there a good solution?
>>>
>>>
>>>
>>> if(array_key_exists($k,$constraintuno)) {
>>> $constraintuno[$k] .= $s." + ";
>>> }
>>>
>>> might work?
>>>
>> and if the key doesn't exist? Once again, the point is that I am
>> trying to insert an item into an array at a key position that doesn't
>> exist yet, and I have no way a priori to know which keys will exist.
>> Surely this cannot be so unusual?
>
>
> if(isset($constraintuno[$k])) {
> $constraintuno[$k] .= $s." + ";
> } else {
> $constraintuno[$k] = $s." + ";
> }
>
>
Ok, if I understand correctly, the problem is that the '.=' is
equivalent to having the variable on the right hand side, and the
warning is about accessing an undefined variable?

T.

 

Navigation:

[Reply to this 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

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