RE: [SMARTY] Looping through an array of objects
| From: | Gary Loescher | Date: | Thu, 17 Oct 2002 17:37:45 +0000 |
| Subject: | RE: [SMARTY] Looping through an array of objects | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-6190@lists.php.net to get a copy of this message | ||
One thing you can do is run your array through array_values
before passing to Smarty. If you don't care about the indexes,
this will re-index starting from zero while keeping the order
the same.
Or, you can just use foreach :)
Gary
>-----Original Message-----
>From: Philippe Desaulniers [mailto:philippe.desaulniers@averna.com]
>Sent: Thursday, October 17, 2002 10:09 AM
>To: 'Josh Johnson'; smarty-general@lists.php.net
>Subject: RE: [SMARTY] Looping through an array of objects
>
>
>Thanks, that works.
>
>I think I caught on to something: { section } assumes that
>$myObjArray is
>indexed by integer values, starting at 0... ...since the two
>items I had
>in $myObjArray happened to have indexes '5' and '6', { section
>} never saw
>them.
>
>I'd have to test it, but maybe with proper indexes ('0' and
>'1') the code
>I posted actually works...
>
>thanks again
>
>phil
>
>
>> -----Original Message-----
>> From: Josh Johnson [mailto:mailing_lists@allusiveimage.com]
>> Sent: October 17, 2002 10:55 AM
>> To: 'Philippe Desaulniers'; smarty-general@lists.php.net
>> Subject: RE: [SMARTY] Looping through an array of objects
>>
>>
>> I'd use a foreach...
>>
>> {foreach from=$myObjArray item=this_object}
>> <li>{$this_object->property}</li>
>> {/foreach}
>>
>> -----Original Message-----
>> From: Philippe Desaulniers [mailto:filou@histrion.org]
>> Sent: Wednesday, October 16, 2002 11:30 PM
>> To: smarty-general@lists.php.net
>> Subject: [SMARTY] Looping through an array of objects
>>
>> Hello,
>>
>> I'm trying to loop in a section, through an array of
>objects. Is there
>> any way to get to my object properties?
>>
>> An example of what I'd like it to do is this:
>>
>> {section name=sec1 loop=$myObjArray}
>> <li>{$myObjectArray[sec1]->myObjectProperty}
>> {/section}
>>
>> Thanks,
>>
>> phil
>>
>>
>>
>>
>> --
>> Smarty General Mailing List (http://smarty.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>>
>> --
>> Smarty General Mailing List (http://smarty.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>
>
>--
>Smarty General Mailing List (http://smarty.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php
>
>