Correct way to check if an array element exists

Author Message

Eirik Alfstad Johansen

Tuesday 15 March 2005 4:10:49 am

Hi,

I'm using the following template code to decide which option in a drop down box that should be selected:

{section name=Child loop=$partner_accounts}
<option value="{$:key}"  {switch match=$level.partner_objects[$:key]}{case match=true}SELECTED{/case}{case}{/case}{/switch}>{$:item}</option>
{/section}

The code works fine, but the debug gives the following error:

No such attribute for array(1): *$:key*

Of course, the attribute with the specific key will not always be present, and that's exactly the purpose of the check. So, how can I make my code "debug-friendly"?

Sincerely,

Eirik Alfstad Johansen
http://www.netmaking.no/

liu spider

Tuesday 15 March 2005 9:11:49 am

try this:
you can use isset($level.partner_objects[$:key]} to test whether the variable is availalbe.

http://liucougar.scim-im.org
SCIM Input Method Platform
http://scim.sf.net
SJSD Online Editor
http://sf.net/projects/sjsd

Hans Melis

Tuesday 15 March 2005 9:19:17 am

Actually, the template function is: <b>is_set()</b>. The isset() function is the PHP variant.

Hans
http://blog.hansmelis.be

Eirik Alfstad Johansen

Wednesday 16 March 2005 12:57:21 am

Thanks a lot, guys! I changed it, and now the debug output looks nice and tidy. Oh, happy days. :)

Sincerely,

Eirik Alfstad Johansen
http://www.netmaking.no/

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.