Re: iterating through object structure



JamesG <mailmehere@xxxxxxxxx> wrote in news:1193843101.021717.143420@
19g2000hsx.googlegroups.com:

Hi,

I have a data structure as follows (print_r($data)):

Array
(
[0] => stdClass Object
(
[FIELD1] => 2355
[FIELD2] => 123
[FIELD3] => 1.25
)

[1] => stdClass Object
(
[FIELD1] => 309
[FIELD2] => 122
[FIELD3] => 0.55
)

)

I can't seem to iterate through it,

If I try
foreach($data as $obj) {
echo $obj->FIELD1 + $obj->FIELD2;
}

It only shows the first object, not the rest. What am I doing wrong?

Using a '+' instead of a '.' ?



.



Relevant Pages

  • iterating through object structure
    ... I have a data structure as follows ): ... I can't seem to iterate through it, ... foreach($data as $obj) { ... It only shows the first object, ...
    (comp.lang.php)
  • Re: Iterating all forms
    ... I'm trying to iterate all controls within each form. ... each control within each form. ... Dim obj As AccessObject, dbs As Object ...
    (microsoft.public.access.formscoding)
  • Re: Need Algorithm or Data Structure for Organizing "Hierarchical" Data
    ... You can iterate over it with either a depth-first ... or breadth-first search. ... multiple children; I have multiple parents; I'm completely unrelated ... delegate for each existing item in the data structure. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: More Efficient: Hashtable or List cont.....
    ... Ignacio Machin ... My app needs to potentially store a large number of custom objects and be ... Is using enumerators to iterate through the data structure a good idea? ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: is parameter an iterable?
    ... >> for item in obj: ... >> except TypeError, msg: ... you can be sure it isn't going to try to iterate ...
    (comp.lang.python)