SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Patience... bronze trophy solidcodes's Avatar
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    936
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    How to echo this using foreach()?

    Hi guys

    I have this array with object below,
    Code:
    Array
    (
        [0] => stdClass Object
            (
                [email] => admin@admin.com
            )
    
        [1] => stdClass Object
            (
                [email] => iridion_us@yahoo.com
            )
    
        [2] => stdClass Object
            (
                [email] => solidcodes@gmail.com
            )
    
    )

    Now how do I echo the value emails using foreach?

    Actually I can access each email by using this codes below
    Code:
        $email[0]->email;
    But I dunno how to echo all of the emails using foreach()?

    Thank you very much in advanced.
    Quality codes are optimized and tested...
    Click here for inspiration..

  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,197
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    You would iterate over each array index like so

    PHP Code:
    var $myArray = array();

    foreach (
    $myArray as $emailAddress) {
        echo 
    $emailAddress->email '<br>';

    That's it, of course $myArray would be your array variable.

  3. #3
    Patience... bronze trophy solidcodes's Avatar
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    936
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    @chris

    Thanks dude it works!
    Quality codes are optimized and tested...
    Click here for inspiration..


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •