Re: unable to use vars in foreach
| From: | Jonathan Villa | Date: | Mon, 15 Nov 2004 04:48:16 +0000 |
| Subject: | Re: unable to use vars in foreach | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-202011@lists.php.net to get a copy of this message | ||
ah yes!!!! thanks!!!! both worked...
I had written a function to this... I knew there had to be a much easier
way!!!
>
> On Sunday, November 14, 2004, at 08:36PM, Jonathan Villa <jvilla@e37.net>
> wrote:
>
>>>
>>> On Sunday, November 14, 2004, at 08:24PM, Jonathan Villa
>>> <jvilla@e37.net>
>>> wrote:
>>>>
>>>>$modules = simplexml_load_file(MODULES);
>>>>
>>>
>>> Are you certain that MODULES has been defined()? And what do you get
>>> when
>>> you print_r($modules)?
>>>
>>> -ryan
>>>
>>
>>Yes MODULES is defined. It's defined in an include file. In my loop,
>>when I echo the $mod->postName the values print just fine. My issue is
>> in
>>the conditional.
>
> AHA!
>
> Here's what I think's going on (sorry I don't have time to investigate it
> myself)....
>
> $mod->postName is a simplexml object. Due to some php5 magic, when used
> it a situation that calls for a string (like echo $xmlobj), it echos the
> proper value. However, when using it as an array subscript does not appear
> to qualify as this situation. To solve this try either:
>
> $post[(string)$xmlobj]
> OR
> $post[strval($xmlobj)]
>
> I hope this is clear and helpful.
>
> -ryan
>