ACCESS VALUES WITHIN CLASS WITHIN AN ARRAY

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Shawn Hamzee

    #1

    ACCESS VALUES WITHIN CLASS WITHIN AN ARRAY

    I have the following construct (printed with print_r):

    Array
    (
    [0]=> Classes Object
    (
    [_my_id] => 001
    [_my_name] => John
    )
    [1]=> Classes Object
    (
    [_my_id] => 003
    [_my_name] => Jill
    )
    )

    What is the syntax to access _my_id and _my_name in for loop.

    I have this but it doesn't work:
    -for ($I = 0; $I < count($myarrays _name); $I++) {
    print $myarrays_name[$I]=>Classes->_my_id
    }

    Thanks for the help.

  • Andy Jeffries

    #2
    Re: Access values within class within array

    On Wed, 21 Jun 2006 15:26:39 +0000, Shawn Hamzee wrote:[color=blue]
    > What is the syntax to access _my_id and _my_name in for loop.
    >
    > I have this but it doesn't work:
    > -for ($I = 0; $I < count($myarrays _name); $I++) {
    > print $myarrays_name[$I]=>Classes->_my_id
    > }[/color]

    for ($I = 0; $I < count($myarrays _name); $I++) {
    print $myarrays_name[$I]->_my_id;
    }

    or simpler:

    foreach ($myarrays_name as $obj) {
    print $obj->_my_id;
    }

    Cheers,


    Andy

    --
    Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer
    http://www.gphpedit.org | PHP editor for Gnome 2
    http://www.andyjeffries.co.uk | Personal site and photos

    Comment

    Working...